title: Getting a byte array as a string in url params
body: <p>Basically, here's my problem: I have a device connected to SigFox which sends 12 bytes of data, which is then rerouted to my golang server using a callback. I tried going the usual route, and decoding the information sent by the callback as a json with <code>json.NewDecoder(r.Body).Decode(&amp;m)</code>, where <code>m</code> is a struct that contains the information sent by the SigFox api on the callback, aka:</p>
  
  <pre><code>type SigFoxMessage struct {
      Time int64 `json:"time"` // I'm getting an epoch timestamp, which I then convert to time.Time
      Data [12]byte `json:"data"`
      Lat int `json:"lat"`
      Lng int `json:"lng"`
  }
  </code></pre>
  
  <p>However, this was always giving me an EOF error, and so I decided to go with <code>r.ParseForm()</code>, and <code>r.Form["key"]</code>. The only problem with this new approach is that it returns the values of the parameters as strings, which isn't a big deal when dealing with the <code>int</code>s and the <code>int64</code>, as I can just use the <code>strconv</code> package. The problem is the 12 bytes of data.</p>
  
  <p>Since they are received as a string, that means I get something like <code>"3132333435363738393130"</code> (the 12 bytes in hex, so 2 characters per byte is a certainty), which I want to convert to <code>[12]byte{31, 32, 33, 34, 35, 36, 37, 38, 39, 31, 30}</code>. But I can't find anyway to do this besides actually implementing a function to parse it. I tried searching for string to byte array conversion, but all I can find are ways to turn byte arrays into strings (which would be turing my <code>[12]byte{'1', '2', '3', '4', '5', '6', '7', '8', '9', '1', '0'}</code> into <code>"12345678910"</code>, and which doesn't interest me), or how to turn strings into array of characters (<code>"3132333435363738393130" -&gt; []byte{'3', '1', '3', ... }</code>), which also doesn't interest me.</p>
  
  <p>Anyways, is there an actual way to do it without having to write the code to parse it?</p>
  
  <p>Also, any ideas why the json decoder might not have worked?</p>
  
  <p><strong>Edit:</strong> I should have put this right away, this is what the params of the request look like:</p>
  
  <p><code>?time=1507834946&amp;data=3132333435363738393130&amp;lat=-8.0&amp;lng=-35.0</code></p>
  
  <p><strong>Edit 2:</strong> The data parameter has the bytes in hex, so every two characters correspond to one byte, ranging from <code>00</code> to <code>ff</code>. The example case I provided was a counting error when trying to send the message with SigFox, and has only 11 bytes. From what I've seen of Go, that shouldn't be a problem, as I believe it would then complete the missing byte, so I don't think that was the reason json decoder failed, but I'll try it with the correct number of bytes now.</p>