ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
Validate数据验证 === 详细规则[https://godoc.org/gopkg.in/go-playground/validator.v8#hdr-Baked\_In\_Validators\_and\_Tags](https://godoc.org/gopkg.in/go-playground/validator.v8#hdr-Baked_In_Validators_and_Tags) ~~~ type Login struct { User string `form:"user" binding:"required"` Password string `form:"password" binding:"required"` } func main() { app := gin.Default() app.POST("/login", func(ctx *gin.Context) { login := &Login{} if err := ctx.ShouldBind(login);err != nil { log.Println(err.Error()) ctx.String(400,"you input error") return } ctx.JSON(200,login) }) app.Run(":8085") } ~~~