encodable a good

Former-commit-id: a0afebd82dfd256ec70c02c607af2a9b3b4b046f
This commit is contained in:
bel
2019-06-22 08:58:54 -06:00
parent 730cf1e15a
commit be065c5dcb
12 changed files with 260 additions and 86 deletions

22
config/encodable.go Normal file
View File

@@ -0,0 +1,22 @@
package config
import (
"bytes"
"encoding/gob"
)
type Encodable struct{}
func (e *Encodable) Encode() ([]byte, error) {
buff := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buff)
err := enc.Encode(e)
return buff.Bytes(), err
}
func (e *Encodable) Decode(b []byte) error {
buff := bytes.NewBuffer(b)
dec := gob.NewDecoder(buff)
err := dec.Decode(e)
return err
}

View File

@@ -34,6 +34,7 @@ func TestNew(t *testing.T) {
}
}
}()
os.Args = []string{"a", "-db", "map"}
if err := New(); err != nil {
t.Fatal(err)
}

7
config/stoppable.go Normal file
View File

@@ -0,0 +1,7 @@
package config
type Stoppable struct{}
func (s Stoppable) Stopped() <-chan struct{} {
return Values().Ctx.Done()
}