From ccd45219eee87a5e70e7d6e7734050fef963fc7e Mon Sep 17 00:00:00 2001 From: ZGGSONG Date: Tue, 19 Oct 2021 19:44:52 +0800 Subject: [PATCH] update --- MyForm/.idea/.gitignore | 8 ++++++ MyForm/.idea/MyFormDemo.iml | Bin 0 -> 4436 bytes MyForm/.idea/modules.xml | 8 ++++++ MyForm/.idea/vcs.xml | 6 ++++ MyForm/login.gtpl | 12 ++++++++ MyForm/main.go | 56 ++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 MyForm/.idea/.gitignore create mode 100644 MyForm/.idea/MyFormDemo.iml create mode 100644 MyForm/.idea/modules.xml create mode 100644 MyForm/.idea/vcs.xml create mode 100644 MyForm/login.gtpl create mode 100644 MyForm/main.go 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 0000000000000000000000000000000000000000..7648199a71c9f47d684c2dfcfd0c5aaab66c263e GIT binary patch literal 4436 zcmeCEm0894s*yp^Lsi=+V1rxLZdJMcRNsKqxAd3rLNldT#o0tOR8&r`1-pp({z=N7W*E){6pr#t*dqW5`v4_I9^Zd ze8Zn5UGshG@txe#DGxWZshzCIH~kf_ds8FaEYZv3cjMiB_YAHD3tNwh-)4w^d!p&I zbIzXi@8qsuJCb2C#p}RV$8|ntr&qT~7x4&&RLi*Y3%Z|NR@PbOW|n+zxofYCb>y#& zuhx_oJWk!5P-Wcr?NRx~r$(!O&E9*9o8$bOo2nNg59d$6_PuWc<5j)c374n;sgpU8 z<{ ZqwdL7Yh8@lG!7}ew#xH5!OnEG5diA{ur2@q literal 0 HcmV?d00001 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) + } +}