Add methods to use storage through the package itself

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
kolaente 2020-10-04 22:14:10 +02:00
parent 75d2405fca
commit 3a305631db
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 28 additions and 0 deletions

View File

@ -17,8 +17,30 @@
package keyvalue
import (
"code.vikunja.io/api/pkg/modules/keyvalue/memory"
)
type Storage interface {
Put(key string, value interface{}) (err error)
Get(key string) (value interface{}, err error)
Del(key string) (err error)
}
var store Storage
func InitStorage() {
store = memory.NewStorage()
}
func Put(key string, value interface{}) error {
return store.Put(key, value)
}
func Get(key string) (value interface{}, err error) {
return store.Get(key)
}
func Del(key string) (err error) {
return store.Del(key)
}

View File

@ -24,6 +24,12 @@ type Storage struct {
mutex sync.Mutex
}
func NewStorage() *Storage {
s := &Storage{}
s.store = make(map[string]interface{})
return s
}
func (s *Storage) Put(key string, value interface{}) (err error) {
s.mutex.Lock()
defer s.mutex.Unlock()