title: go programming POST FormValue can't be printed
body: <p>Before I being a bit of background, I am very new to go programming language. I am running go on Win 7, latest go package installer for windows. I'm not good at coding but I do like some challenge of learning a new language. I wanted to start learn Erlang but found go very interesting based on the GO I/O videos in youtube.</p>
  
  <p>I'm having problem with capturing POST form values in GO. I spend three hours yesterday to get go to print a POST form value in the browser and failed miserably. I don't know what I'm doing wrong, can anyone point me to the right direction? I can easily do this in another language like C#, PHP, VB, ASP, Rails etc. I have search the entire interweb and haven't found a working sample. Below is my sample code.</p>
  
  <p><strong>Here is Index.html page</strong></p>
  
  <pre><code>{{ define "title" }}Homepage{{ end }}
  
  {{ define "content" }}
      &lt;h1&gt;My Homepage&lt;/h1&gt;
  
      &lt;p&gt;Hello, and welcome to my homepage!&lt;/p&gt;
      &lt;form method="POST" action="/"&gt;
      &lt;p&gt; Enter your name : &lt;input type="text" name="username"&gt; &lt;/P&gt;
      &lt;p&gt; &lt;button&gt;Go&lt;/button&gt;
      &lt;/form&gt;
      &lt;br /&gt;&lt;br /&gt;
  
  {{ end }}
  </code></pre>
  
  <p><strong>Here is the base page</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;title&gt;{{ template "title" . }}&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;section id="contents"&gt;
              {{ template "content" . }}
          &lt;/section&gt;
          &lt;footer id="footer"&gt;
              My homepage 2012 copy
          &lt;/footer&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>now some go code</strong></p>
  
  <pre><code>    package main
  
  import (
      "fmt"
      "http"
      "strings"
      "html/template"
  
  )
  
  var index = template.Must(template.ParseFiles(
    "templates/_base.html",
    "templates/index.html",
  ))
  
  
  func GeneralHandler(w http.ResponseWriter, r *http.Request) {
      index.Execute(w, nil)
       if r.Method == "POST" {
          a := r.FormValue("username")
          fmt.Fprintf(w, "hi %s!",a); //&lt;-- this variable does not rendered in the browser!!!
  
      }
  }
  
  func helloHandler(w http.ResponseWriter, r *http.Request) {
      remPartOfURL := r.URL.Path[len("/hello/"):] 
      fmt.Fprintf(w, "Hello %s!", remPartOfURL)
  }
  
  
  func main() {
      http.HandleFunc("/", GeneralHandler)
      http.HandleFunc("/hello/", helloHandler)
      http.ListenAndServe("localhost:81", nil)
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>PS: Very tedious to add four space before every line of code in stackoverflow especially when you are copy pasting. Didn't find it very user friendly or is there an easier way?</p>