examples icon indicating copy to clipboard operation
examples copied to clipboard

Might be a bug in the example custom-validation

Open Tensorfengsheng1926 opened this issue 5 years ago • 4 comments

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

Tensorfengsheng1926 avatar Feb 18 '20 04:02 Tensorfengsheng1926

I encountered the same problem

lkburning avatar Feb 21 '20 03:02 lkburning

due to [email protected] 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.

dasheyuan avatar Mar 10 '20 09:03 dasheyuan

thank you replay发自我的华为手机-------- 原始邮件 --------发件人: 陈圆 [email protected]日期: 2020年3月10日周二 傍晚5:30收件人: gin-gonic/examples [email protected]抄送: burningceramicsinmesary [email protected], Comment [email protected]主 题: Re: [gin-gonic/examples] Might be a bug in the example custom-validation (#29)due to [email protected] 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.

lkburning avatar Mar 10 '20 10:03 lkburning

@dasheyuan Can you please post a more details?

Update: nvm, thanks!

rahulnpadalkar avatar Mar 18 '20 10:03 rahulnpadalkar