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")
}
~~~