func (s *Store) Put(obj Object) error {
	value, err := json.Marshal(obj)
	if err != nil {
		return fmt.Errorf("failed to encode meta data: %v", err)
	}
	if err := s.backend.Put(s.current.Name, obj.Key(), value); err != nil {
		return fmt.Errorf("failed to put meta data: %v", err)
	}
	s.trieLock.Lock()
	s.trie.Insert(patricia.Prefix(obj.Key()), struct{}{})
	s.trieLock.Unlock()
	return nil
}
Put writes the 'obj' into backend storage.
package meta
import (
	"encoding/json"
	"fmt"
	"reflect"
	"sync"
	"github.com/tchap/go-patricia/patricia"
)
var (
	MetaJSONFile = "meta.json"
)
type Bucket struct {
	Name string
	Type reflect.Type
}
func (b *Bucket) NewObject() Object {
	return reflect.New(b.Type).Interface().(Object)
}
type Config struct {
	Driver  string
	Buckets []Bucket
	BaseDir string
}
type Object interface {
	Key() string
}
type Store struct {
	Config
	trieLock *sync.Mutex  
	trie     *patricia.Trie
	current  *Bucket
	backend  Backend
}
func NewStore(cfg Config) (*Store, error) {
	if len(cfg.Buckets) < 1 {
		return nil, fmt.Errorf("config bucket can not be empty")
	}
	if cfg.Driver == "" {
		cfg.Driver = DefaultStore
	}
	if _, ok := backendFactory[cfg.Driver]; !ok {
		return nil, fmt.Errorf("store driver %s not found", cfg.Driver)
	}
	backend, err := backendFactory[cfg.Driver](cfg)
	if err != nil {
		return nil, fmt.Errorf("create driver %s failed: %v", cfg.Driver, err)
	}
	s := &Store{
		Config:   cfg,
		backend:  backend,
		trieLock: new(sync.Mutex),
		trie:     patricia.NewTrie(),
	}
	keys := []string{}
	for _, bucket := range cfg.Buckets {
		k, err := s.backend.Keys(bucket.Name)
		if err != nil {
			return nil, err
		}
		keys = append(keys, k...)
	}
	for _, key := range keys {
		s.trie.Insert(patricia.Prefix(key), struct{}{})
	}
	s = s.Bucket(cfg.Buckets[0].Name)
	if s == nil {
		return nil, fmt.Errorf("failed to new bucket store")
	}
	return s, nil
}
func (s *Store) Bucket(name string) *Store {
	if name == "" {
		if s.current == nil {
			return nil
		}
		return s
	}
	var pb *Bucket
	for _, b := range s.Buckets {
		if name == b.Name {
			pb = &b
			break
		}
	}
	if pb == nil {
		return nil
	}
	return &Store{
		Config:   s.Config,
		backend:  s.backend,
		current:  pb,
		trieLock: s.trieLock,
		trie:     s.trie,
	}
}