-
Notifications
You must be signed in to change notification settings - Fork 8k
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Binding UUID in header failed #3036
Comments
It's not Gin's bug. type A struct {
ID uuid.UUID `header:"ID"`
} should be type A struct {
ID string `header:"ID"`
} If you wanna transfer it to |
@Bisstocuz Thank you. The UUID in body and URI can be bind correctly. Have "uuid in header cannot be bind directly" been mentioned somewhere? |
Here is binding code: case reflect.Array:
if !ok {
vs = []string{opt.defaultValue}
}
if len(vs) != value.Len() {
return false, fmt.Errorf("%q is not valid value for %s", vs, value.Type().String())
}
return true, setArray(vs, value, field) |
If you expect to receive a https://github.com/go-playground/validator#format You can also choose different func main() {
type A struct {
ID string `header:"ID" binding:"required,uuid"`
}
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
var a A
err := c.ShouldBindHeader(&a)
if err != nil {
panic(err)
}
c.JSON(200, gin.H{
"message": a.ID,
})
})
r.Run()
} |
Description
I'm trying to bind a UUID header field. It did not bind successfully but reported an error.
How to reproduce
Expectations
requests.get("http://127.0.0.1:8088/ping", headers={"ID":"1b524196-100a-4ff6-8881-bf0e1e509b1d"})
-> 200
Actual result
Environment
The text was updated successfully, but these errors were encountered: