mholt/binding

Add a way to know what field names are present

Closed this issue · 2 comments

The PUT/PATCH idioms are common to API design and the way binder currently works, there is no way to if a field is present in the request or if it's just an empty value.

We could either allow pointers, e.g.

type QeueForm struct {
    AdId             *string `json:"ad_id"`
    Type             *string `json:"ad_type"`
}

or use a struct tag to populate the fields present in the request:

type QeueForm struct {
    Fields        []string "fields" 
    AdId            string `json:"ad_id"`
    Type            string `json:"ad_type"`
}

I prefer the "fields" tag, is this something you would like to see added to the binder?

Thanks,

Troy

Support for pointer types was added last week.

Yeah what he said. 👍 Try go get -u github.com/mholt/binding