package mainimport ( "encoding/json" "fmt" "github.com/gin-gonic/gin" "net/http")func main() { r := gin.Default() r.POST("/json", func(c *gin.Context) { data,_ := c.GetRawData() var m map[string]interface{} _ = json.Unmarshal(data, &m) c.JSON(http.StatusOK,m) }) r.LoadHTMLGlob("./temp/*") r.GET("/user/add", func(c *gin.Context) { c.HTML(http.StatusOK, "useradd.html", gin.H{}) }) r.POST("/user/add", func(c *gin.Context) { username := c.PostFormArray("username") password := c.PostFormArray("password") fmt.Println(username, "goubibibi", password) c.JSON(http.StatusOK,gin.H{ "msg":"ok", "username":username, "password": password, }) }) r.Run()}
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <form action="/user/add" method="post"> <p>username: <input type="text" name="username"></p> <p>password: <input type="text" name="password"></p> <button type="submit"></button> </form></head><body></body></html>