neato
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import "local/rproxy3/storage/packable"
|
import (
|
||||||
|
"errors"
|
||||||
|
"local/rproxy3/storage/packable"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrNotFound = errors.New("not found")
|
||||||
|
|
||||||
type DB interface {
|
type DB interface {
|
||||||
Get(string, string, packable.Packable) error
|
Get(string, string, packable.Packable) error
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"local/rproxy3/storage/packable"
|
"local/rproxy3/storage/packable"
|
||||||
)
|
)
|
||||||
@@ -46,7 +45,7 @@ func (m Map) Get(ns, key string, value packable.Packable) error {
|
|||||||
m[ns] = make(map[string][]byte)
|
m[ns] = make(map[string][]byte)
|
||||||
}
|
}
|
||||||
if _, ok := m[ns][key]; !ok {
|
if _, ok := m[ns][key]; !ok {
|
||||||
return errors.New("not found")
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
return value.Decode(m[ns][key])
|
return value.Decode(m[ns][key])
|
||||||
}
|
}
|
||||||
@@ -55,6 +54,12 @@ func (m Map) Set(ns, key string, value packable.Packable) error {
|
|||||||
if _, ok := m[ns]; !ok {
|
if _, ok := m[ns]; !ok {
|
||||||
m[ns] = make(map[string][]byte)
|
m[ns] = make(map[string][]byte)
|
||||||
}
|
}
|
||||||
|
if value == nil {
|
||||||
|
if _, ok := m[ns][key]; ok {
|
||||||
|
delete(m[ns], key)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
b, err := value.Encode()
|
b, err := value.Encode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user