Last active
February 24, 2024 00:07
-
-
Save miguelmota/5bfa2b6ab88f439fe0da0bfb1faca763 to your computer and use it in GitHub Desktop.
Golang interface to bytes using gob encoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/gob" | |
"bytes" | |
) | |
func GetBytes(key interface{}) ([]byte, error) { | |
var buf bytes.Buffer | |
enc := gob.NewEncoder(&buf) | |
err := enc.Encode(key) | |
if err != nil { | |
return nil, err | |
} | |
return buf.Bytes(), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesnt work also.
Unable to unmarshal: invalid character 'e' looking for beginning of value