summaryrefslogtreecommitdiff
path: root/objectstore
diff options
context:
space:
mode:
authorPablo M. Bermudo Garay <pablombg@gmail.com>2022-02-08 19:15:48 +0100
committerPablo M. Bermudo Garay <pablombg@gmail.com>2022-02-10 13:14:19 +0100
commit81763bb1b4bcd1cb8094696e31e0711d965e173c (patch)
tree5d9bb52fc94d034018edf071444eb657b20c61ef /objectstore
parenta30c96160333edb002e5b1cc18ef20b07ddc78ee (diff)
Refactor memory backend
Simplify code path returning errors earlier.
Diffstat (limited to 'objectstore')
-rw-r--r--objectstore/memory_backend.go45
1 files changed, 24 insertions, 21 deletions
diff --git a/objectstore/memory_backend.go b/objectstore/memory_backend.go
index a21abca..735a649 100644
--- a/objectstore/memory_backend.go
+++ b/objectstore/memory_backend.go
@@ -21,38 +21,41 @@ func NewMemBackend() *MemObjectStore {
}
func (os *MemObjectStore) CreateObject(bucketId string, objectId string, object string) {
- if bucket, ok := os.buckets[bucketId]; ok {
- bucket.objects[objectId] = object
- } else {
- bucket := memBucket{}
+ bucket, ok := os.buckets[bucketId]
+ if !ok {
+ bucket = memBucket{}
bucket.objects = make(map[string]string)
-
- bucket.objects[objectId] = object
os.buckets[bucketId] = bucket
}
+
+ bucket.objects[objectId] = object
}
func (os *MemObjectStore) GetObject(bucketId string, objectId string) (string, error) {
- if bucket, ok := os.buckets[bucketId]; ok {
- if object, ok := bucket.objects[objectId]; ok {
- return object, nil
- } else {
- return "", fmt.Errorf("Object not found")
- }
- } else {
+ bucket, ok := os.buckets[bucketId]
+ if !ok {
return "", fmt.Errorf("Bucket not found")
}
+
+ object, ok := bucket.objects[objectId]
+ if !ok {
+ return "", fmt.Errorf("Object not found")
+ }
+
+ return object, nil
}
func (os *MemObjectStore) DeleteObject(bucketId string, objectId string) error {
- if bucket, ok := os.buckets[bucketId]; ok {
- if _, ok := bucket.objects[objectId]; ok {
- delete(bucket.objects, objectId)
- return nil
- } else {
- return fmt.Errorf("Object not found")
- }
- } else {
+ bucket, ok := os.buckets[bucketId]
+ if !ok {
return fmt.Errorf("Bucket not found")
}
+
+ _, ok = bucket.objects[objectId]
+ if !ok {
+ return fmt.Errorf("Object not found")
+ }
+
+ delete(bucket.objects, objectId)
+ return nil
}