title: How to append byte array to slice of bytes in Go
body: <p>I have a simple bit of code that i am trying to understand, but am struggling to work out how to get it to work properly.</p>
  
  <p>The general idea is i want to pass some data, and convert it into a byte array. Then i want to apply the length of the byte array at the first index of my byte slice, then add the byte array to end of the slice.</p>
  
  <p>This is what it tried:</p>
  
  <pre><code>    var slice []byte
      myString := "Hello there"
  
      stringAsByteArray := []byte(myString) //convert my string to byte array
  
  
      slice[0] = byte(len(stringAsByteArray)) //length of string as byte array
  
      append(slice, stringAsByteArray) 
  </code></pre>
  
  <p>So the idea is the first byte of <code>slice</code> contains the number of <code>len(b)</code> then following on from that, the actual string message as a series of bytes.</p>
  
  <p>But i get:</p>
  
  <pre><code>cannot use stringAsByteArray (type []byte) as type byte in append
  append(slice, stringAsByteArray) evaluated but not used
  </code></pre>