Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iota results in missing parameter #95

Closed
MattNewberry opened this issue Aug 18, 2014 · 4 comments
Closed

iota results in missing parameter #95

MattNewberry opened this issue Aug 18, 2014 · 4 comments

Comments

@MattNewberry
Copy link
Contributor

Synopsis:
When using iota to default a const group to a 0 value, and sending a 0 value via a JSON payload, the binding process fails believing the required value is missing.

Schema:

const (
    EventTypeEntry = iota
    EventTypeExit
)

Event struct {
        Type      int    `bson:"type" json:"type" binding:"required"`
        Timestamp string `bson:"timestamp" json:"timestamp" binding:"required"`
    }

JSON:

{
    "events": [
        {
            "timestamp": "2014-08-18T14:03:26.761-0400",
            "type": 0
        }
    ]
}

Response:

[GIN] 2014/08/18 - 14:08:03 | 400 |     78.894us | 127.0.0.1:52575 POST /v1/events
Error #01: Required Type 
     Meta: Operation aborted
@manucorporat
Copy link
Contributor

I know, we are working in a completely new validation system
#67

@manucorporat
Copy link
Contributor

@MattNewberry check out the new validation options: http://godoc.org/gopkg.in/bluesuncorp/validator.v5
Gin now uses that library internally, so you could use:

Event struct {
        Type      int    `bson:"type" json:"type" binding:"min=0,max=2"`
        Timestamp string `bson:"timestamp" json:"timestamp" binding:"required"`
}

how does it sounds?

@nazwa
Copy link

nazwa commented May 24, 2015

Nicely done with the new form validation. I can't test it any time soon, but do you think this will have any noticeable performance impact on simple forms?

@manucorporat
Copy link
Contributor

@nazwa i don't think so, we just added one more branch: if structField.Kind() == reflect.Struct {
anyway I just optimized it a little bit:
967e623

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants