diff options
Diffstat (limited to 'storage')
-rw-r--r-- | storage/memory_storage.go | 9 | ||||
-rw-r--r-- | storage/storage.go | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/storage/memory_storage.go b/storage/memory_storage.go index 0c90981..b9ed54a 100644 --- a/storage/memory_storage.go +++ b/storage/memory_storage.go @@ -1,6 +1,7 @@ package storage import ( + "code.laria.me/petrific/config" "code.laria.me/petrific/objects" ) @@ -16,6 +17,10 @@ func NewMemoryStorage() Storage { } } +func MemoryStorageFromConfig(conf config.Config, name string) (Storage, error) { + return NewMemoryStorage(), nil +} + func (ms MemoryStorage) Get(id objects.ObjectId) ([]byte, error) { b, ok := ms.objects[id.String()] if !ok { @@ -39,3 +44,7 @@ func (ms MemoryStorage) Set(id objects.ObjectId, typ objects.ObjectType, raw []b func (ms MemoryStorage) List(typ objects.ObjectType) ([]objects.ObjectId, error) { return ms.bytype[typ], nil } + +func (MemoryStorage) Close() error { + return nil +} diff --git a/storage/storage.go b/storage/storage.go index 45b1973..0729fe1 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -2,6 +2,7 @@ package storage import ( "bytes" + "code.laria.me/petrific/config" "code.laria.me/petrific/objects" "errors" "fmt" @@ -17,6 +18,14 @@ type Storage interface { Has(id objects.ObjectId) (bool, error) Set(id objects.ObjectId, typ objects.ObjectType, raw []byte) error List(typ objects.ObjectType) ([]objects.ObjectId, error) + + Close() error +} + +type CreateStorageFromConfig func(conf config.Config, name string) (Storage, error) + +var StorageTypes = map[string]CreateStorageFromConfig{ + "memory": MemoryStorageFromConfig, } func SetObject(s Storage, o objects.RawObject) (id objects.ObjectId, err error) { |