From 24f84ebddeeede603238ecc5fc6903291983774a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 2 Jun 2021 07:27:14 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'main.go'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index b12f3b4..2d89994 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,33 @@ package main -import "fmt" +import ( + "fmt" + "net/http" + "strings" + "log" +) -func main() { - fmt.Println(HelloWorld()) -} - -// HelloWorld is a function that returns a string containing "hello world". func HelloWorld() string { return "hello world" +} + +func sayhelloName(w http.ResponseWriter, r *http.Request) { + r.ParseForm() // 解析参数,默认是不会解析的 + fmt.Println(r.Form) // 这些信息是输出到服务器端的打印信息 + 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!") // 这个写入到 w 的是输出到客户端的 +} + +func main() { + http.HandleFunc("/", sayhelloName) // 设置访问的路由 + err := http.ListenAndServe(":8080", nil) // 设置监听的端口 + if err != nil { + log.Fatal("ListenAndServe: ", err) + } } \ No newline at end of file