Last active
December 28, 2015 10:29
-
-
Save andreadipersio/7486291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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