Gin: Binding failed on int required field when value is 0

Created on 5 May 2016  路  4Comments  路  Source: gin-gonic/gin

my form struct is like this:

type XXX struct {
  Offset int `binding:"required"`
}

And my test case is like this:

curl http://127.0.0.1:8080/xxx?offset=0

Most helpful comment

You need a form:"offset" tag:

type XXX struct {
  Offset int `form:"offset" binding:"required"`
}

All 4 comments

You need a form:"offset" tag:

type XXX struct {
  Offset int `form:"offset" binding:"required"`
}

Is there an error, or is it just passing validation when you would expect it too?

If it's the latter then offset will always exist due to go's a static nature, but could use a pointer to integer and use the "exists" tag instead of "required" more details can be found https://github.com/go-playground/validator/issues/225 even though it's about bool, the same principal applies.

I came across the same problem, got it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cxk280 picture cxk280  路  3Comments

oryband picture oryband  路  3Comments

Bloomca picture Bloomca  路  3Comments

ccaza picture ccaza  路  3Comments

nxvl picture nxvl  路  3Comments