martini-contrib / binding

Martini handler for mapping and validating a raw request into a structure.
MIT License
140 stars 47 forks source link

Binding “cannot return value obtained from unexported field or method” #38

Closed Raul-diffindo closed 9 years ago

Raul-diffindo commented 9 years ago

I have the following route:

m.Post("/users", binding.Bind(models.User{}), func(user models.User, r render.Render)

And I receive the following error message when I try to do a Post request:

"PANIC: reflect.Value.Interface: cannot return value obtained from unexported field or method"

My model is:

type User struct {
    id         int
    UUID       string    `json:"uuid"`
    Username   string    `json:"userName" form:"userName" binding:"required"`
    Firstname  string    `json:"firstName" form:"Firstname" binding:"required`
    Lastname   string    `json:"lastName" form:"Lastname" binding:"required`
    Email      string    `json:"email" form:"Email" binding:"required`
    IsActive   bool      `json:"isActive"`
    DateJoined time.Time `json:"dateJoined"`
}

Sorry. The problem was the attribute "id". If I set this as "Id" works perfectly or if I set the tag form:"-" too.

Thank you and sorry for the question. You can delete it.

mholt commented 9 years ago

Ah, no problem. Forgetting to export fields used by other packages is easy to do.