Implement namespace optional arg
This commit is contained in:
10
bolt.go
10
bolt.go
@@ -13,10 +13,11 @@ func NewBolt(path string) (*Bolt, error) {
|
||||
}, err
|
||||
}
|
||||
|
||||
func (b *Bolt) Get(key string) ([]byte, error) {
|
||||
func (b *Bolt) Get(key string, ns ...string) ([]byte, error) {
|
||||
namespace := resolveNamespace(ns)
|
||||
var result []byte
|
||||
err := b.db.View(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket([]byte(DefaultNamespace))
|
||||
bkt := tx.Bucket([]byte(namespace))
|
||||
if bkt == nil {
|
||||
return ErrNotFound
|
||||
}
|
||||
@@ -29,9 +30,10 @@ func (b *Bolt) Get(key string) ([]byte, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (b *Bolt) Set(key string, value []byte) error {
|
||||
func (b *Bolt) Set(key string, value []byte, ns ...string) error {
|
||||
namespace := resolveNamespace(ns)
|
||||
return b.db.Update(func(tx *bolt.Tx) error {
|
||||
bkt, err := tx.CreateBucketIfNotExists([]byte(DefaultNamespace))
|
||||
bkt, err := tx.CreateBucketIfNotExists([]byte(namespace))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user