diff options
Diffstat (limited to 'objectstore')
| -rw-r--r-- | objectstore/memory_backend.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/objectstore/memory_backend.go b/objectstore/memory_backend.go index 735a649..09f7d8a 100644 --- a/objectstore/memory_backend.go +++ b/objectstore/memory_backend.go @@ -4,13 +4,17 @@ // https://creativecommons.org/publicdomain/zero/1.0/legalcode package objectstore -import "fmt" +import ( + "fmt" + "sync" +) type memBucket struct { objects map[string]string } type MemObjectStore struct { + sync.Mutex buckets map[string]memBucket } @@ -21,6 +25,9 @@ func NewMemBackend() *MemObjectStore { } func (os *MemObjectStore) CreateObject(bucketId string, objectId string, object string) { + os.Lock() + defer os.Unlock() + bucket, ok := os.buckets[bucketId] if !ok { bucket = memBucket{} @@ -32,6 +39,9 @@ func (os *MemObjectStore) CreateObject(bucketId string, objectId string, object } func (os *MemObjectStore) GetObject(bucketId string, objectId string) (string, error) { + os.Lock() + defer os.Unlock() + bucket, ok := os.buckets[bucketId] if !ok { return "", fmt.Errorf("Bucket not found") @@ -46,6 +56,9 @@ func (os *MemObjectStore) GetObject(bucketId string, objectId string) (string, e } func (os *MemObjectStore) DeleteObject(bucketId string, objectId string) error { + os.Lock() + defer os.Unlock() + bucket, ok := os.buckets[bucketId] if !ok { return fmt.Errorf("Bucket not found") |
