Get retrieves the value for a key in the bucket. Returns a nil value if the key does not exist or if the key is a nested bucket. The returned value is only valid for the life of the transaction. The returned memory is owned by bbolt and must never be modified; writing to this memory might corrupt th
(key []byte)
| 431 | // The returned value is only valid for the life of the transaction. |
| 432 | // The returned memory is owned by bbolt and must never be modified; writing to this memory might corrupt the database. |
| 433 | func (b *Bucket) Get(key []byte) []byte { |
| 434 | k, v, flags := b.Cursor().seek(key) |
| 435 | |
| 436 | // Return nil if this is a bucket. |
| 437 | if (flags & common.BucketLeafFlag) != 0 { |
| 438 | return nil |
| 439 | } |
| 440 | |
| 441 | // If our target node isn't the same key as what's passed in then return nil. |
| 442 | if !bytes.Equal(key, k) { |
| 443 | return nil |
| 444 | } |
| 445 | return v |
| 446 | } |
| 447 | |
| 448 | // Put sets the value for a key in the bucket. |
| 449 | // If the key exist then its previous value will be overwritten. |