使用Golang实现一个简单的web,并且得到表单数据 go 语言真的是太方便了,部署超级简单啊,爽歪歪啊哈哈
package main
import (
"net/http"
"log"
"fmt"
"html/template"
)
func main(){
http.HandleFunc("/",index)
http.HandleFunc("/login",login)
err:=http.ListenAndServe(":9900",nil)
if err != nil {
log.Fatal("服务错误",err)
}
}
func index(w http.ResponseWriter, r *http.Request){
fmt.Println("index")
t,_:=template.ParseFiles("./index.html")
t.Execute(w,nil)
}
func login(w http.ResponseWriter, r *http.Request){
var formData = make(map[string]string)
r.ParseForm()
formData["name"] = r.Form["name"][0]
formData["pass"] = r.Form["pass"][0]
r.ParseMultipartForm(32 << 20)
t,_:=template.New("./login.html").Parse("你的登入名:{{.name}}----你的密码是{{.pass}}")
t.Execute(w,formData)
}