I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …
:date_long | 1 min Read
Go request.FormValue('xyz')
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
http.HandleFunc("/", index)
http.Handle("/favicon.ico", http.NotFoundHandler())
http.ListenAndServe(":8080", nil)
}
func index(w http.ResponseWriter, r *http.Request) {
user := r.FormValue("user")
surname := r.FormValue("surname")
w.Header().Set("Content-type", "text/html")
fmt.Printf("requested url: %v\n", r.URL)
fmt.Printf("input variable user: %v\n", user)
// io.WriteString(w, "Hello from Go dude! Username: " + v + "\n")
io.WriteString(w, `
<p>Now the form requires POST (user)</p>
<form method="post">
<input type="text" name="user">
<input type="submit">
</form>
` + user + `<p>Now the form requires GET (surname)</p>
<form method="get">
<input type="text" name="surname">
<input type="submit">
</form>` + surname)
}