commit ccd45219eee87a5e70e7d6e7734050fef963fc7e Author: ZGGSONG Date: Tue Oct 19 19:44:52 2021 +0800 update diff --git a/MyForm/.idea/.gitignore b/MyForm/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/MyForm/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/MyForm/.idea/MyFormDemo.iml b/MyForm/.idea/MyFormDemo.iml new file mode 100644 index 0000000..7648199 Binary files /dev/null and b/MyForm/.idea/MyFormDemo.iml differ diff --git a/MyForm/.idea/modules.xml b/MyForm/.idea/modules.xml new file mode 100644 index 0000000..ffcc32f --- /dev/null +++ b/MyForm/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/MyForm/.idea/vcs.xml b/MyForm/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/MyForm/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MyForm/login.gtpl b/MyForm/login.gtpl new file mode 100644 index 0000000..bdffaf4 --- /dev/null +++ b/MyForm/login.gtpl @@ -0,0 +1,12 @@ + + + + + +
+ 用户名: + 密码: + +
+ + diff --git a/MyForm/main.go b/MyForm/main.go new file mode 100644 index 0000000..0803ab0 --- /dev/null +++ b/MyForm/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + "html/template" + "log" + "net/http" + "strings" +) + +func sayHelloName(w http.ResponseWriter, r *http.Request) { + err := r.ParseForm() + if err != nil { + return + } + 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, "")) + } + _, err = fmt.Fprintf(w, "hello astaxie!") + if err != nil { + return + } +} + +func login(w http.ResponseWriter, r *http.Request) { + err := r.ParseForm() + if err != nil { + return + } + fmt.Println("method:", r.Method) //获取请求的方法 + if r.Method == "GET" { + t, _ := template.ParseFiles("login.gtpl") + err := t.Execute(w, nil) + if err != nil { + return + } + } else { + //请求的是登陆数据,那么执行登陆的逻辑判断 + fmt.Println("username:", r.Form["username"]) + fmt.Println("password:", r.Form["password"]) + } +} + +func main() { + http.HandleFunc("/", sayHelloName) + http.HandleFunc("/login", login) + err := http.ListenAndServe(":9090", nil) + if err != nil { + log.Fatal("ListenAddServer: ", err) + } +}