Initial commit: bolt, map, leveldb support and test
This commit is contained in:
47
map.go
Normal file
47
map.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Map map[string][]byte
|
||||
|
||||
func NewMap() Map {
|
||||
m := make(map[string][]byte)
|
||||
n := Map(m)
|
||||
return n
|
||||
}
|
||||
|
||||
func (m Map) String() string {
|
||||
s := ""
|
||||
for k, v := range m {
|
||||
if s != "" {
|
||||
s += ",\n"
|
||||
}
|
||||
s += fmt.Sprintf("[%s]:[%s]", k, v)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (m Map) Close() error {
|
||||
m = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Map) Get(key string) ([]byte, error) {
|
||||
if _, ok := m[key]; !ok {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return m[key], nil
|
||||
}
|
||||
|
||||
func (m Map) Set(key string, value []byte) error {
|
||||
if value == nil {
|
||||
if _, ok := m[key]; ok {
|
||||
delete(m, key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
m[key] = value
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user