diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-04-15 23:45:06 -0400 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-04-15 23:45:06 -0400 |
commit | 2505b9a7dcca1e5d9d80ebfc6be7afcd97ba02dd (patch) | |
tree | 4d351709b0ec5d5eb1803b59c84e868c07889208 /cmd | |
parent | Fix race detector CI. (diff) | |
download | dedo-2505b9a7dcca1e5d9d80ebfc6be7afcd97ba02dd.tar.gz dedo-2505b9a7dcca1e5d9d80ebfc6be7afcd97ba02dd.tar.xz |
Return bucket from CreateBucket() functions.
This commit changes the API for:
Tx.CreateBucket()
Tx.CreateBucketIfNotExists()
Bucket.CreateBucket()
Bucket.CreateBucketIfNotExists()
These functions now return the *Bucket and error instead of just the error.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/bolt/get_test.go | 3 | ||||
-rw-r--r-- | cmd/bolt/import.go | 8 |
2 files changed, 6 insertions, 5 deletions
diff --git a/cmd/bolt/get_test.go b/cmd/bolt/get_test.go index d491971..7b7c3a0 100644 --- a/cmd/bolt/get_test.go +++ b/cmd/bolt/get_test.go @@ -45,7 +45,8 @@ func TestGetKeyNotFound(t *testing.T) { SetTestMode(true) open(func(db *bolt.DB, path string) { db.Update(func(tx *bolt.Tx) error { - return tx.CreateBucket([]byte("widgets")) + _, err := tx.CreateBucket([]byte("widgets")) + return err }) db.Close() output := run("get", path, "widgets", "foo") diff --git a/cmd/bolt/import.go b/cmd/bolt/import.go index 7554ae7..bcb7d2e 100644 --- a/cmd/bolt/import.go +++ b/cmd/bolt/import.go @@ -41,7 +41,8 @@ func Import(path string, input string) { } // Create the bucket if it doesn't exist. - if err := tx.CreateBucketIfNotExists(message.Key); err != nil { + b, err := tx.CreateBucketIfNotExists(message.Key) + if err != nil { return fmt.Errorf("create bucket: %s", err) } @@ -52,7 +53,6 @@ func Import(path string, input string) { } // Import all the values into the bucket. - b := tx.Bucket(message.Key) if err := importBucket(b, children); err != nil { return fmt.Errorf("import bucket: %s", err) } @@ -70,7 +70,8 @@ func importBucket(b *bolt.Bucket, children []*rawMessage) error { // Bucket messages are handled recursively. if child.Type == "bucket" { // Create the bucket if it doesn't exist. - if err := b.CreateBucketIfNotExists(child.Key); err != nil { + subbucket, err := b.CreateBucketIfNotExists(child.Key) + if err != nil { return fmt.Errorf("create bucket: %s", err) } @@ -81,7 +82,6 @@ func importBucket(b *bolt.Bucket, children []*rawMessage) error { } // Import subbucket. - subbucket := b.Bucket(child.Key) if err := importBucket(subbucket, subchildren); err != nil { return fmt.Errorf("import bucket: %s", err) } |