seaweedfs/go/metastore/memory_backing.go
Chris Lu 5cb6590eae add metastore, switching sequence to use it
metastore is for storing metadata. This will be used later when moving
to distributed master mode.
2013-11-05 01:59:00 -08:00

38 lines
730 B
Go

package metastore
import (
"fmt"
"path"
)
//this is for testing only
type MetaStoreMemoryBacking struct {
m map[string][]byte
}
func NewMetaStoreMemoryBacking() MetaStoreMemoryBacking {
mms := MetaStoreMemoryBacking{}
mms.m = make(map[string][]byte)
return mms
}
func (mms MetaStoreMemoryBacking) Set(val []byte, elem ...string) error {
mms.m[path.Join(elem...)] = val
return nil
}
func (mms MetaStoreMemoryBacking) Get(elem ...string) (val []byte, err error) {
var ok bool
val, ok = mms.m[path.Join(elem...)]
if !ok {
return nil, fmt.Errorf("Missing value for %s", path.Join(elem...))
}
return
}
func (mms MetaStoreMemoryBacking) Has(elem ...string) (ok bool) {
_, ok = mms.m[path.Join(elem...)]
return
}