I recently tried appending two byte array slices in Go and came across some odd errors. My code is:
one:=make([]byte, 2)
two:=make([]byte, 2)
one[0]=0x00
one[1]=0x01
two[0]=0x02
two[1]=0x03
log.Printf("%X", append(one[:], two[:]))
three:=[]byte{0, 1}
four:=[]byte{2, 3}
five:=append(three, four)
And the errors are:
cannot use four (type []uint8) as type uint8 in append
cannot use two[:] (type []uint8) as type uint8 in append
Which taken into consideration the alleged robustness of Go's slices shouldn't be a problem:
http://code.google.com/p/go-wiki/wiki/SliceTricks
What am I doing wrong, and how should I go about appending two byte arrays?
question from:https://stackoverflow.com/questions/8461462/how-can-i-use-go-append-with-two-byte-slices-or-arrays