Package Mainimport ("FMT" "Log" "Net/http" "strings") Func Sayhelloname (w http. Responsewriter, R *http. Request) {r.parseform ()//parse parameter, default is FMT not resolved. 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!")//output to the client information}func Main () {http. Handlefunc ("/", Sayhelloname)//set access to the 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!
Building a WEB server with Golang HTTP packets