summaryrefslogtreecommitdiff
path: root/objectstore
diff options
context:
space:
mode:
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
}