Skip to content

Instantly share code, notes, and snippets.

@jafstar
Created July 19, 2012 14:11
Show Gist options
  • Save jafstar/3144203 to your computer and use it in GitHub Desktop.
Save jafstar/3144203 to your computer and use it in GitHub Desktop.
Go Form Results
package app
import (
"net/http"
"fmt"
)
func forms(w http.ResponseWriter, r *http.Request){
//GET
if r.Method == "POST"{
//HELPER FUNCTION
formVal := func(val string)string{
return r.FormValue(val)
}
//FORM STRUCT
type Form struct {
Q string
A string
}
//SLICE
formSlice := []Form {
Form{"Name", "name"},
Form{"Email", "email"},
Form{"Phone", "phone"},
}
//FOR
for _,val:= range formSlice {
fmt.Fprintln(w, val.Q + " : " + formVal(val.A))
}
//END POST
}
//END FUNC
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment