package Util
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/gob"
|
|
)
|
|
|
|
func ToBytes(key interface{}) ([]byte, error) {
|
|
var (
|
|
buf bytes.Buffer
|
|
enc *gob.Encoder
|
|
err error
|
|
)
|
|
enc = gob.NewEncoder(&buf)
|
|
err = enc.Encode(key)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return buf.Bytes(), nil
|
|
|
|
}
|