Add memory implementation for keyvalue store

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

View File

@ -0,0 +1,24 @@
// Copyright 2020 Vikunja and contriubtors. All rights reserved.
//
// This file is part of Vikunja.
//
// Vikunja is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vikunja is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
package keyvalue
type Storage interface {
Put(key string, value interface{}) (err error)
Get(key string) (value interface{}, err error)
Del(key string) (err error)
}

View File

@ -0,0 +1,45 @@
// Copyright 2020 Vikunja and contriubtors. All rights reserved.
//
// This file is part of Vikunja.
//
// Vikunja is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vikunja is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
package memory
import "sync"
type Storage struct {
store map[string]interface{}
mutex sync.Mutex
}
func (s *Storage) Put(key string, value interface{}) (err error) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.store[key] = value
return nil
}
func (s *Storage) Get(key string) (value interface{}, err error) {
s.mutex.Lock()
defer s.mutex.Unlock()
return s.store[key], nil
}
func (s *Storage) Del(key string) (err error) {
s.mutex.Lock()
defer s.mutex.Unlock()
delete(s.store, key)
return nil
}