package main import ( "gee" "net/http" ) func main() { //// 封装前 //obj := map[string]interface{}{} //obj["name"] = "dug" //obj["age"] = 18 //http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // w.Header().Set("Content-Type", "application/json") // w.WriteHeader(http.StatusOK) // encoder := json.NewEncoder(w) // if err := encoder.Encode(obj); err != nil { // http.Error(w, err.Error(), http.StatusInternalServerError) // } //}) //_ = http.ListenAndServe(":9000", nil) r := gee.New() r.GET("/", func(c *gee.Context) { c.Html(http.StatusOK, "

Hello Gee

") }) r.GET("/hello", func(c *gee.Context) { c.String(http.StatusOK, "hello %s, you're at %s\n", c.Query("name"), c.Path) }) r.POST("/login", func(c *gee.Context) { c.Json(http.StatusOK, gee.H{ "username": c.PostForm("username"), "password": c.PostForm("password"), }) }) r.Run(":9000") }