A bucket is a named grouping of key-value pairs inside a BoltDB database. It gives a persistent store a dedicated namespace: a TaskStore records its bucket name and uses that bucket for task data while the database file provides persistence. section 11.9
A bucket participates in the persistent store lifecycle in several steps:
- Declare its name in the store configuration, alongside the database filename and file mode. section 11.9
Task bucket
NewTaskStore("tasks.db", 0600, "tasks") opens the persistent database, records tasks as key-value pairs in the tasks bucket, and reuses that bucket when the application starts again. section 11.11
Listing 11.21 The persistent version of our task store, called TaskStore
import (
// previous imports omitted
"github.com/boltdb/bolt"
)
type TaskStore struct {
Db *bolt.DB
DbFile string
FileMode os.FileMode
Bucket string
}
Inspect the minimal TaskStore structure to see how a bucket name connects a BoltDB database to persistent task operations. section 11.9








