split db and bolt to store interface

This commit is contained in:
ston1th 2018-09-11 14:50:53 +02:00
commit 7e77fd7d27
14 changed files with 419 additions and 545 deletions

28
pkg/store/marshal.go Normal file
View file

@ -0,0 +1,28 @@
package store
import (
"bytes"
"encoding/gob"
)
type Marshaler interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, v interface{}) error
}
type gobMarshaler struct{}
func NewGOB() Marshaler {
return gobMarshaler{}
}
func (gobMarshaler) Marshal(v interface{}) (b []byte, err error) {
buf := new(bytes.Buffer)
err = gob.NewEncoder(buf).Encode(v)
b = buf.Bytes()
return
}
func (gobMarshaler) Unmarshal(data []byte, v interface{}) error {
return gob.NewDecoder(bytes.NewBuffer(data)).Decode(v)
}