forked from electricdusk/rushlink
Refactor database login into a separate module
This commit is contained in:
24
pkg/gobmarsh/marshal.go
Normal file
24
pkg/gobmarsh/marshal.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user