Refactor database login into a separate module

This commit is contained in:
Daan Sprenkels
2019-12-03 23:08:58 +01:00
parent 8b87cd0f8a
commit 0cfad96b68
10 changed files with 489 additions and 430 deletions

24
pkg/gobmarsh/marshal.go Normal file
View File

@@ -0,0 +1,24 @@
package rushlink
// Easier marshalling to and from gob encoding
import (
"bytes"
"encoding/gob"
)
// Marshal serializes the value in v to a byte buffer.
func Marshal(v interface{}) ([]byte, error) {
b := new(bytes.Buffer)
err := gob.NewEncoder(b).Encode(v)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}
// Unmarshal deserializes the data in data into the object in v.
func Unmarshal(data []byte, v interface{}) error {
b := bytes.NewBuffer(data)
return gob.NewDecoder(b).Decode(v)
}