Use the binary.Write
method of the encoding/binary package.
buf := new(bytes.Buffer)
err := binary.Write(buf, binary.BigEndian, uint16(259))
if err != nil {
fmt.Println("binary.Write failed:", err)
}
// This should be two bytes with your encoded integer.
fmt.Println(buf.Bytes())