These are chat archives for gin-gonic/gin

Jan 2019
Jan 31 02:17
HI, a bit desperated here...I'm having issues trying to c.Bind(&nestedStruct) when the request is a json payload. However, It does work fine if the request is made via form-urlencoded. Any ideas?
the problem is json won't bind to the nested struct completely, just the main struct.
Jan 31 02:49
// User is the model for the user table.
type User struct {
    Phone    string `gorm:"column:phone;varchar(15);not null;unique_index" form:"phone" json:"phone" bindind:"required"`
    Password string `gorm:"column:password;not null;" form:"password" json:"password" bindind:"required"`
    Profile Profile `json:"profile" binding:"required,dive"`
// Profile is the model for the profile table.
type Profile struct {
    FirstName string `form:"first_name" json:"first_name"`
    LastName  string `form:"last_name" json:"last_name"`
    Email     string `gorm:"type:varchar(110);" form:"email" json:"email"`

And the post body payload (JSON) is:

    "phone": "99345678918",
    "first_name": "David4",
    "last_name": "Velasquez1",
    "password": "1234",
    "email": "c",

the code:

// Get the user fields from the request and bind them to a user struct
    user := &models.User{}
    err := c.ShouldBind(user)

This will bind only phoneand password but not the others