This is a creation in Article, where the information may have evolved or changed.
package mainimport ("FMT" "Log" "Net/http" " Strings ") Func sayhelloname (w http. Responsewriter, r *http. Request) {r.parseform () //parsing parameters, default is the FMT that will not be parsed. Println (R.form) //These are server-side printing information fmt. PRINTLN ("Path", r.url. Path) fmt. PRINTLN ("scheme", r.url. Scheme) fmt. Println (r.form["Url_long"]) for k, v := range r.form {fmt. Println ("Key:", k) fmt. Println ("Val:", strings. Join (v, ""))}fmt. fprintf (w, "hello world!") //outputs the information}func main () {http to the client. Handlefunc ("/", sayhelloname) //set the access route err := http. Listenandserve (": 8080", nil) //set the listening port If err != nil {log. Fatal ("listenandserve: ", err)}}
Run the program go run xxx.go
Enter in the browser successively
http://localhost:8080
Output result Hello world!