Initial commit: bolt, map, leveldb support and test

This commit is contained in:
Bel LaPointe
2019-03-13 14:06:46 -06:00
commit 8a1cf7104c
7 changed files with 220 additions and 0 deletions

47
map.go Normal file
View 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
}