How to retrieve form-data as map (like PHP and Ruby) in Go (Golang)
<p>I'm a PHP Dev. But currently moving to Golang... I'm trying to retrieve data from a Form (Post method):</p>

<pre><code>&lt;!-- A really SIMPLE form --&gt;
&lt;form class="" action="/Contact" method="post"&gt;
  &lt;input type="text" name="Contact[Name]" value="Something"&gt;   
  &lt;input type="text" name="Contact[Email]" value="Else"&gt;
  &lt;textarea name="Contact[Message]"&gt;For this message&lt;/textarea&gt;
  &lt;button type="submit"&gt;Submit&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>In PHP I would simple use this to get the data:</p>

<pre><code>&lt;?php 
   print_r($_POST["Contact"])
?&gt;
// Output would be something like this:
Array
(
    [Name] =&gt; Something
    [Email] =&gt; Else
    [Message] =&gt; For this message
)
</code></pre>

<p>BUT in go... either I get one by one or the whole thing but not the Contact[] Array only such as PHP</p>

<p>I thought about 2 solutions:</p>

<p>1) Get one by one:</p>

<pre><code>// r := *http.Request
err := r.ParseForm()

if err != nil {
    w.Write([]byte(err.Error()))
    return
}

contact := make(map[string]string)

contact["Name"] = r.PostFormValue("Contact[Name]")
contact["Email"] = r.PostFormValue("Contact[Email]")
contact["Message"] = r.PostFormValue("Contact[Message]")

fmt.Println(contact)

// Output
map[Name:Something Email:Else Message:For this Message]
</code></pre>

<p>Note that the map keys are the whole: "Contact[Name]"...</p>

<p>2) Range whole map <code>r.Form</code> and "parse|obtain" those values with Prefix 
"Contact[" and then replacing "Contact[" and "]" with empty string 
so I can get the Form array Key only such the PHP Example</p>

<p>I went for this work around by my own but... ranging over the whole form may not be a good idea (?)</p>

<pre><code>// ContactPost process the form sent by the user
func ContactPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
    err := r.ParseForm()

    if err != nil {
        w.Write([]byte(err.Error()))
        return
    }

    contact := make(map[string]string)

   for i := range r.Form {
       if strings.HasPrefix(i, "Contact[") {
           rp := strings.NewReplacer("Contact[", "", "]", "")
           contact[rp.Replace(i)] = r.Form.Get(i)
       }
   }

    w.Write([]byte(fmt.Sprint(contact)))
}
//Output
map[Name:Something Email:Else Message:For this Message]
</code></pre>

<p>Both solutions give me the same output... But in the 2nd example I don't necessarily need to know the keys of "Contact[]"</p>

<p>I know... I may just forget about that "Form Array" and use <code>name="Email"</code> on my inputs and retrieve one by one but... I've passing through some scenarios where I use ONE form that contain more than 2 arrays of data and do different things with each one, like ORMs</p>

<p><strong>Question 1</strong>: Is there a easier way to get my Form Array as an actual map in Golang like PHP does?</p>

<p><strong>Question 2</strong>: Should I retrieve the data one by one (Tedious as much and I may change the Form data at some point and recompile...) or iterate the whole thing as I've done in the 2nd example.</p>

<p>Sorry for my bad English... Thanks in advance!</p>