💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ 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) } } ~~~