encodable a good
Former-commit-id: a0afebd82dfd256ec70c02c607af2a9b3b4b046f
This commit is contained in:
22
config/encodable.go
Normal file
22
config/encodable.go
Normal 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
|
||||
}
|
||||
@@ -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
7
config/stoppable.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
type Stoppable struct{}
|
||||
|
||||
func (s Stoppable) Stopped() <-chan struct{} {
|
||||
return Values().Ctx.Done()
|
||||
}
|
||||
Reference in New Issue
Block a user