企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ type LoginForm struct { User string `form:"user" binding:"required"` Password string `form:"password" binding:"required"` } func main() { r := gin.Default() r.POST("/login", func(c *gin.Context) { var form LoginForm if c.ShouldBind(&form) == nil { if form.User == "user" && form.Password == "password" { c.JSON(200, gin.H{"status": "login successfully!"}) } else { c.JSON(401, gin.H{"status": "login failed!"}) } } }) r.Run(":8888") } ~~~ ~~~ func main() { r := gin.Default() r.POST("/form_post", func(c *gin.Context) { message := c.PostForm("message") nick := c.DefaultPostForm("nick", "anonymous") c.JSON(200, gin.H{ "status": "posted", "message": message, "nick": nick, }) }) r.Run(":8888") } ~~~