Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for Bucket.Delete() in README.md #421

Merged
merged 1 commit into from
Mar 14, 2023
Merged

Conversation

cenkalti
Copy link
Member

Resurrect #338

The example is similar to the examples for `Bucket.Put()` and `Bucket.Get()` functions, so it does not breaks the layout. Signed-off-by: Sarthak2143 <sarthaktomar2143@gmail.com> .

Co-authored-by: Benjamin Wang <wachao@vmware.com>
Signed-off-by: Cenk Alti <cenkalti@gmail.com>
```go
db.Update(func (tx *bolt.Tx) error {
b := tx.Bucket([]byte("MyBucket"))
err := b.Delete([]byte("answer"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the bucket "MyBucket" doesn't exist, then the returned b is nil; accordingly b.Delete will panic due to nil pointer error. I am thinking we should add a check something like if b != nil.

All examples in README do not have such check, so we can address this in a separate PR to update all examples. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nil check can be omitted in examples for simplicity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense.

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a minor comment. Please feel free to address it in a separate PR.

Thank you @cenkalti

@ahrtr ahrtr added this to the v1.4.0 milestone Mar 14, 2023
@ahrtr ahrtr merged commit a5e2643 into etcd-io:master Mar 14, 2023
@ahrtr ahrtr removed this from the v1.4.0 milestone May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants