diff --git a/pkg/modules/keyvalue/keyvalue.go b/pkg/modules/keyvalue/keyvalue.go new file mode 100644 index 000000000..d2765875e --- /dev/null +++ b/pkg/modules/keyvalue/keyvalue.go @@ -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 . + +package keyvalue + +type Storage interface { + Put(key string, value interface{}) (err error) + Get(key string) (value interface{}, err error) + Del(key string) (err error) +} diff --git a/pkg/modules/keyvalue/memory/memory.go b/pkg/modules/keyvalue/memory/memory.go new file mode 100644 index 000000000..17a58884c --- /dev/null +++ b/pkg/modules/keyvalue/memory/memory.go @@ -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 . + +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 +}