MCPcopy
hub / github.com/etcd-io/bbolt / ForEach

Method ForEach

bucket.go:585–596  ·  view source on GitHub ↗

ForEach executes a function for each key/value pair in a bucket. Because ForEach uses a Cursor, the iteration over keys is in lexicographical order. If the provided function returns an error then the iteration is stopped and the error is returned to the caller. The provided function must not modify

(fn func(k, v []byte) error)

Source from the content-addressed store, hash-verified

583// the error is returned to the caller. The provided function must not modify
584// the bucket; this will result in undefined behavior.
585func (b *Bucket) ForEach(fn func(k, v []byte) error) error {
586 if b.tx.db == nil {
587 return errors.ErrTxClosed
588 }
589 c := b.Cursor()
590 for k, v := c.First(); k != nil; k, v = c.Next() {
591 if err := fn(k, v); err != nil {
592 return err
593 }
594 }
595 return nil
596}
597
598func (b *Bucket) ForEachBucket(fn func(k []byte) error) error {
599 if b.tx.db == nil {

Callers

nothing calls this directly

Calls 3

CursorMethod · 0.95
FirstMethod · 0.80
NextMethod · 0.80

Tested by

no test coverage detected