Add login

This commit is contained in:
2020-01-05 23:20:38 +01:00
parent dc396a300f
commit c0926ffea0
35 changed files with 1647 additions and 39 deletions

View File

@@ -0,0 +1,37 @@
package fake
import (
"encoding/json"
"hamster-tycoon/storage/dao"
"hamster-tycoon/utils"
"time"
"github.com/allegro/bigcache"
)
type DatabaseFake struct {
Cache *bigcache.BigCache
}
func NewDatabaseFake() dao.Database {
cache, err := bigcache.NewBigCache(bigcache.DefaultConfig(time.Minute))
if err != nil {
utils.GetLogger().WithError(err).Fatal("Error while instantiate cache")
}
return &DatabaseFake{
Cache: cache,
}
}
func (db *DatabaseFake) save(key string, data []interface{}) {
b, err := json.Marshal(data)
if err != nil {
utils.GetLogger().WithError(err).Errorf("Error while marshal fake %s", key)
db.Cache.Set(key, []byte("[]"))
return
}
err = db.Cache.Set(key, b)
if err != nil {
utils.GetLogger().WithError(err).Errorf("Error while saving fake %s", key)
}
}