func (b *Backend) CreateNamespace(
	conf stori.NamespaceConfig) error {
	keySlice := []string{"namespace", conf.Name}
	fields := make(map[string]string)
	fields["blob-storage-limit"] = string(conf.BlobStorageLimit)
	fields["repository-limit"] = string(conf.RepositoryLimit)
	fields["status"] = string(stori.NamespaceActive)
	for k, v := range conf.Labels {
		keySlice := []string{"label", k}
		labelKey := strings.Join(keySlice, ":")
		fields[labelKey] = v
	}
	updateFunc := func(tx *buntdb.Tx) error {
		for k, v := range fields {
			s := make([]string, len(keySlice))
			copy(s, keySlice)
			s = append(s, k)
			absoluteKey := strings.Join(s, ":")
			set(tx, absoluteKey, v)
		}
		return nil
	}
	b.db.Update(updateFunc)
	return nil
}
CreateNamespace creates a new namespace in the registry.
package inmem
import (
	"encoding/json"
	"strings"
	"github.com/atlaskerr/stori/schema/storage/backend"
	"github.com/atlaskerr/stori/stori"
	"github.com/tidwall/buntdb"
)
type Backend struct {
	schema []byte
	db     *buntdb.DB
}
func New() (*Backend, error) {
	b := new(Backend)
	source := backend.InmemConfigLoaderFunc()
	rawJSON, err := json.Marshal(source.JsonSource())
	if err != nil {
		return nil, err
	}
	b.schema = rawJSON
	memDB, err := buntdb.Open(":memory:")
	if err != nil {
		return nil, err
	}
	b.db = memDB
	return b, nil
}
func (b *Backend) GetSchema() []byte {
	return b.schema
}
func (b *Backend) setupIndexes() {
	b.db.CreateIndex("namespaces", "namespace:*")
}
func (b *Backend) Setup(interface{}) error {
	b.setupIndexes()
	return nil
}
func set(tx *buntdb.Tx, key, value string) {
	tx.Set(key, value, nil)
}