import (
"bytes"
"encoding/binary"
"encoding/gob"
"fmt"
)
func str_to_byte(src string) []byte {
//strSlice := []string{src}
buffer := &bytes.Buffer{}
gob.NewEncoder(buffer).Encode(src)
return buffer.Bytes()
}
func uint64_to_byte(src uint64) []byte {
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, src)
return buf
}
func main() {
var u uint64
u = 128
bytes := uint64_to_byte(u)
fmt.Println(bytes)
str := "128"
bytes = str_to_byte(str)
fmt.Println(bytes)
}
有疑问加站长微信联系(非本文作者)