多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ package main import ( "net/http" "fmt" "html/template" "strconv" ) type User struct { Name string Age int City } type City struct { Name1 string Name2 string Name3 string } func login(w http.ResponseWriter, r *http.Request) { method := r.Method if method == "GET" { t, err := template.ParseFiles("./demo.html") if err != nil { fmt.Fprint(w, "load demo.html failed") return } t.Execute(w, nil) } else if method == "POST" { r.ParseForm() name := r.FormValue("name") age, _ := strconv.Atoi(r.FormValue("age")) t, err := template.ParseFiles("./login2.html") if err != nil { fmt.Println("load login.html failed") } u := make([]User, 10, 10) for i := 0; i < 10; i++ { u = append(u, User{Name: fmt.Sprint(name, i), Age: age, City: City{Name1: "省", Name2: "市", Name3: "区"}}) } //t.Execute(w, User{Name: name, Age: age, City: City{Name1: "省", Name2: "市", Name3: "区"}}) t.Execute(w, u) } } func main() { http.HandleFunc("/login", login) err := http.ListenAndServe(":9090", nil) if err != nil { fmt.Println("ListenAndServe is Error", err) } } ~~~