33 lines
544 B
Go
33 lines
544 B
Go
package storage
|
|
|
|
import "fmt"
|
|
|
|
type MemoryStorage struct {
|
|
Data map[string]any `json:"data"`
|
|
}
|
|
|
|
func (ms *MemoryStorage) Init() error {
|
|
ms.Data = map[string]any{}
|
|
return nil
|
|
}
|
|
|
|
func (ms *MemoryStorage) Cleanup() error {
|
|
return nil
|
|
}
|
|
|
|
func (ms *MemoryStorage) Get(k string) (any, error) {
|
|
v, ok := ms.Data[k]
|
|
if ok {
|
|
return v, nil
|
|
}
|
|
return nil, fmt.Errorf("value '%s' does not exist", k)
|
|
}
|
|
|
|
func (ms *MemoryStorage) Set(k string, v any) error {
|
|
ms.Data[k] = v
|
|
return nil
|
|
}
|
|
|
|
func (ms *MemoryStorage) GetData() any {
|
|
return ms.Data
|
|
}
|