move resolve into package

This commit is contained in:
Bel LaPointe
2021-02-21 12:39:15 -06:00
parent ff8b908ee7
commit 7f2d451ca4
15 changed files with 205 additions and 175 deletions

14
bolt.go
View File

@@ -1,6 +1,10 @@
package storage
import "github.com/boltdb/bolt"
import (
"local/storage/resolve"
"github.com/boltdb/bolt"
)
type Bolt struct {
db *bolt.DB
@@ -14,8 +18,8 @@ func NewBolt(path string) (*Bolt, error) {
}
func (b *Bolt) List(ns []string, limits ...string) ([]string, error) {
namespace := resolveNamespace(ns)
limits = resolveLimits(limits)
namespace := resolve.Namespace(ns)
limits = resolve.Limits(limits)
found := []string{}
err := b.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(namespace))
@@ -33,7 +37,7 @@ func (b *Bolt) List(ns []string, limits ...string) ([]string, error) {
}
func (b *Bolt) Get(key string, ns ...string) ([]byte, error) {
namespace := resolveNamespace(ns)
namespace := resolve.Namespace(ns)
var result []byte
err := b.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket([]byte(namespace))
@@ -50,7 +54,7 @@ func (b *Bolt) Get(key string, ns ...string) ([]byte, error) {
}
func (b *Bolt) Set(key string, value []byte, ns ...string) error {
namespace := resolveNamespace(ns)
namespace := resolve.Namespace(ns)
return b.db.Update(func(tx *bolt.Tx) error {
bkt, err := tx.CreateBucketIfNotExists([]byte(namespace))
if err != nil {