tbotd/vendor/src/github.com/asdine/storm/helpers.go

19 lines
363 B
Go
Raw Normal View History

2016-05-29 18:43:51 +00:00
package storm
import "github.com/asdine/storm/codec"
// toBytes turns an interface into a slice of bytes
func toBytes(key interface{}, encoder codec.EncodeDecoder) ([]byte, error) {
if key == nil {
return nil, nil
}
if k, ok := key.([]byte); ok {
return k, nil
}
if k, ok := key.(string); ok {
return []byte(k), nil
}
return encoder.Encode(key)
}