go-examples/form-ex1/main.go

25 lines
442 B
Go
Raw Normal View History

2017-07-27 17:57:26 +00:00
package main
import (
"html/template"
"net/http"
)
func handleForm(res http.ResponseWriter, req *http.Request) {
data := map[string]string{
"first": req.FormValue("first"),
"last": req.FormValue("last"),
}
tpl, err := template.ParseFiles("form.html")
if err != nil {
http.Error(res, err.Error(), 500)
} else {
tpl.Execute(res, data)
}
}
func main() {
http.HandleFunc("/", handleForm)
http.ListenAndServe(":9000", nil)
}