This is a creation in Article, where the information may have evolved or changed.
HTTP Package Build Web server
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 astaxie!")//output to the client information}func Main () {http. Handlefunc ("/", Sayhelloname) //set access to the route err: = http. Listenandserve (": 9090", nil)//Set the listening port if err! = Nil {log. Fatal ("Listenandserve:", Err)}}
Enter in the browser successively
http://localhost:9090
http://localhost:9090/?url_long=111&url_long=222
The content of the output to the browser is: Hello astaxie!
Server-side Console output:
G:\users\chenjo>go Run Web.go
Map[]
Path/
Scheme
[]
Map[]
Path/favicon.ico
Scheme
[]
map[url_long:[111 222]]
Path/
Scheme
[111 222]
Key:url_long
val:111222
Map[]
Path/favicon.ico
Scheme
[]