You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to bind form data to nested structs, but I'm not sure if I'm doing it correctly. Is there a recommended way to handle form binding with nested structs using the standard library?
My Use Case
I have a form structure with nested fields that I want to bind to corresponding nested structs:
typeUserInfostruct {
Namestring`form:"name"`Sexstring`form:"sex"`
}
typeUserGroupstruct {
Men []UserInfo`form:"men"`Women []UserInfo`form:"women"`
}
typeUserResultsstruct {
WinUserGroup`form:"win"`LoseUserGroup`form:"lose"`
}
funchandler(w http.ResponseWriter, r*http.Request) {
form:=&UserResults{}
iferr:=c.Bind(form); err!=nil {
// error handle
}
// Values are not bound to nested structs
}
What I've Tried
I've attempted to use dot notation in the form field names:
Is there a built-in way to handle nested struct binding with the standard library?
If yes, what is the correct naming convention for form fields?
Is there any documentation I might have missed about this topic?
Environment
Go version: 1.22
Any guidance or best practices would be greatly appreciated. If this functionality isn't currently supported, would it be worth considering as a feature request?
The text was updated successfully, but these errors were encountered:
I'm trying to bind form data to nested structs, but I'm not sure if I'm doing it correctly. Is there a recommended way to handle form binding with nested structs using the standard library?
My Use Case
I have a form structure with nested fields that I want to bind to corresponding nested structs:
What I've Tried
I've attempted to use dot notation in the form field names:
Questions
Environment
Any guidance or best practices would be greatly appreciated. If this functionality isn't currently supported, would it be worth considering as a feature request?
The text was updated successfully, but these errors were encountered: