gin-gonic / examples

A repository to host examples and tutorials for Gin.
https://gin-gonic.com/docs/
MIT License
3.66k stars 638 forks source link

Might be a bug in the example custom-validation #29

Open Tensorfengsheng1926 opened 4 years ago

Tensorfengsheng1926 commented 4 years ago

Hi, in the example Custom validators, (https://github.com/gin-gonic/examples/blob/3a0d22aa344fcf014612f43f5bf21f9c9997fd67/custom-validation/server.go#L32) v, ok := binding.Validator.Engine().(*validator.Validate) returns v=nil and ok=false on my machine. Therefore the validator bookableDate would not be registered.

Environment: Windows 10 Go 1.13 github.com/gin-gonic/gin v1.5.0 github.com/go-playground/validator/v10 v10.2.0

lkburning commented 4 years ago

I encountered the same problem

dasheyuan commented 4 years ago

due to gin@v1.5.0 import gopkg.in/go-playground/validator.v9 so I solved this problem like this: custom-validation/server.go

//"github.com/go-playground/validator/v10"
"gopkg.in/go-playground/validator.v9"

...

CheckIn  time.Time `form:"check_in" binding:"required,bookabledate" time_format:"2006-01-02"`

it works.

lkburning commented 4 years ago

thank you replay发自我的华为手机-------- 原始邮件 --------发件人: 陈圆 notifications@github.com日期: 2020年3月10日周二 傍晚5:30收件人: gin-gonic/examples examples@noreply.github.com抄送: burningceramicsinmesary llk199626@163.com, Comment comment@noreply.github.com主 题: Re: [gin-gonic/examples] Might be a bug in the example custom-validation (#29)due to gin@v1.5.0 import gopkg.in/go-playground/validator.v9 so I solved this problem like this: custom-validation/server.go //"github.com/go-playground/validator/v10" "gopkg.in/go-playground/validator.v9"

...

CheckIn time.Time form:"check_in" binding:"required,bookabledate" time_format:"2006-01-02"

it works.

—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.

rahulnpadalkar commented 4 years ago

@dasheyuan Can you please post a more details?

Update: nvm, thanks!