MCPcopy Create free account
hub / github.com/Apress/pro-go / ProcessFormData

Function ProcessFormData

24 - HTTP Servers/httpserver/forms.go:8–18  ·  view source on GitHub ↗
(writer http.ResponseWriter, request *http.Request)

Source from the content-addressed store, hash-verified

6)
7
8func ProcessFormData(writer http.ResponseWriter, request *http.Request) {
9 if (request.Method == http.MethodPost) {
10 index, _ := strconv.Atoi(request.PostFormValue("index"))
11 p := Product {}
12 p.Name = request.PostFormValue("name")
13 p.Category = request.PostFormValue("category")
14 p.Price, _ = strconv.ParseFloat(request.PostFormValue("price"), 64)
15 Products[index] = p
16 }
17 http.Redirect(writer, request, "/templates", http.StatusTemporaryRedirect)
18}
19
20func init() {
21 http.HandleFunc("/forms/edit", ProcessFormData)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected