Skip to content

Instantly share code, notes, and snippets.

@andreadipersio
Last active December 28, 2015 10:29
Show Gist options
  • Save andreadipersio/7486291 to your computer and use it in GitHub Desktop.
Save andreadipersio/7486291 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
)
func rootHandler(w http.ResponseWriter, r *http.Request) {
// http://golang.org/pkg/net/http/#Request.FormValue
firstName, lastName := r.FormValue("name"), r.FormValue("last_name")
if firstName == "" || lastName == "" {
http.Error(w, "name and last_name are mandatory fields", 400)
} else {
fmt.Fprintf(w, "Hello, %v %v!", firstName, lastName)
}
}
func main() {
http.HandleFunc("/", rootHandler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment