mirror of
https://github.com/go-gitea/bolt.git
synced 2026-07-01 20:35:22 -04:00
Fix prefix scan example
The example is correct in isolation, but if people just copy the loop, it will go into infinite loop when given an empty byte slice.
This commit is contained in:
committed by
GitHub
parent
0d9f544bb9
commit
714f31f39e
@@ -395,7 +395,7 @@ db.View(func(tx *bolt.Tx) error {
|
||||
c := tx.Bucket([]byte("MyBucket")).Cursor()
|
||||
|
||||
prefix := []byte("1234")
|
||||
for k, v := c.Seek(prefix); bytes.HasPrefix(k, prefix); k, v = c.Next() {
|
||||
for k, v := c.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, v = c.Next() {
|
||||
fmt.Printf("key=%s, value=%s\n", k, v)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user