[Advanced] go go a simple server implementation

Time flies, Riyuerusuo, yesterday I finally got myself busy for half a month's wages.

It is said that July 25 has an asteroid passing Earth, if we really hit by an estimated 31 I am not in a good mood, it should be no more direct.

The following code is running a mini-go server

. 1  Package main
 2  
. 3  Import (
 . 4      "FMT"
 . 5      "log"
 . 6      "NET / HTTP"
 . 7      "strings"
 . 8  )
 . 9  
10 FUNC sayhelloName (http.ResponseWriter W, R & lt * http.Request) {
 . 11      r.ParseForm ()   // resolution parameters, the default is not resolved 
12 is      fmt.Println (r.Form)   // information is output to the print information server 
13 is      fmt.Println ( "path", r.URL.Path) / * this information all! ! ! ! ! * / 
14      fmt.Println ( "scheme" , r.URL.Scheme)
 15     fmt.Println (r.Form [ "url_long" ])
 16      for K, V: = Range {r.Form
 . 17          fmt.Println ( "Key:" , K)
 18 is          fmt.Println ( "Val:", strings.Join (V, "" ))
 . 19      }
 20 is      fmt.Fprintf (w, "astaxie the Hello!") // this is written to the output w to the client 
21 is  }
 22 is  
23 is FUNC loginContro (w http.ResponseWriter, R & lt * HTTP .request) {
 24      r.ParseForm ()
 25      fmt.Println (r.Form)
 26 is      fmt.Println ( "path" , r.URL.Path)
 27      fmt.Println ( "scheme" ,
r.URL.Scheme)
28     fmt.Println(r.Form["url_long"])
29     for k, v := range r.Form {
30         fmt.Println("key:", k)
31         fmt.Println("val:", strings.Join(v, ""))
32     }
33     fmt.Fprintf(w, "this is page of login check!")
34 }
35 
36 func main() {
37     http.HandleFunc("/", sayhelloName) //设置访问的路由
38     http.HandleFunc("/login",loginContro)
39     err := http.ListenAndServe(":9090",nil) 40port listening//
     if err != nil {
41         log.Fatal("ListenAndServe: ", err)
42     }
43 }

There's nothing to say, I feel we can easily understand -

Here today friends ~

Guess you like

Origin www.cnblogs.com/sbhyc/p/11284113.html