title: Get post data using golang http package
body: <p>I am new to golang, getting familiar with http package. I am having trouble in getting the post data I am sending using postman.</p>
  
  <p><code>http://localhost:8084/dbTest</code> is my URI. I am passing key: <code>hub_id</code> value: <code>1</code> using form-data. I tried following approaches, </p>
  
  <pre><code>req.ParseForm()
  fmt.Println("hub_id", req.Form["hub_id"])
  req.Form.Get("hub_id")
  </code></pre>
  
  <p>But none of the approach work. I am getting empty response.</p>
  
  <p>Following is my code:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "net/http"
      "log"
  ) 
  
  func dbtest(w http.ResponseWriter, req *http.Request) {
    req.ParseForm()
    fmt.Println("hub_id", req.Form["hub_id"])
    req.Form.Get("hub_id")
    fmt.Println(req.PostFormValue("hub_id")) //response is empty
  }
  
  func main() {
  
      http.HandleFunc("/dbTest", dbtest)
  
    log.Fatal(http.ListenAndServe(":8084", nil))
  }
  </code></pre>
  
  <p>When I print req i get the following:</p>
  
  <pre><code>&amp;{POST /dbTest HTTP/1.1 1 1 map[Origin:[chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop] Connection:[keep-alive] Content-Type:[multipart/form-data; boundary=----WebKitFormBoundarydFOTVjOJMeqOHnS3] Content-Length:[138] Accept-Language:[en-US,en;q=0.8] Cache-Control:[no-cache] Accept-Encoding:[gzip, deflate] Accept:[*/*] User-Agent:[Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36] Postman-Token:[ac7ae3a9-60f6-2146-3f1c-209de7622774]] 0xc210012e70 138 [] false localhost:8084 map[] map[] &lt;nil&gt; map[] 127.0.0.1:34152 /dbTest &lt;nil&gt;}
  </code></pre>
  
  <p><strong>Solution:</strong> I found the solution. Since, content-type is <code>mulipart/form-data</code> I correct way to parse form is to use <code>req.ParseMultipartForm</code> http method.</p>