-
Notifications
You must be signed in to change notification settings - Fork 82
Re-thinking the binding package #28
Description
Quite a few important discussions and pull requests have happened here which I think deserve some attention (all are important, but these are the relevant ones):
- Add type interface{} target as argument to Field.Binder? #17 Add type interface{} target as argument to Field.Binder?
- Introduce a FieldMapFromStruct() to avoid repetitions? #18 Introduce a FieldMapFromStruct() to avoid repetitions? and dynamic (runtime) FieldMap() #19 dynamic (runtime) FieldMap()
- Added Map to support mux.Vars in Gorilla #20 Added Map to support mux.Vars in Gorilla
- Return error interface instead of Errors #22 Return error interface instead of Errors
- Expose *Binder interface for more byte oriented payloads #24 Expose *Binder interface for more byte oriented payloads
To me, two main themes prevail:
- Reduce duplication
- Use interfaces to make the package generic/idiomatic
To make this happen, I'm willing to redesign the whole package and even break the existing API (it's not 1.0 yet anyway) to accomplish more useful, long-living goals. The philosophy behind the package still stands, though: no reflection, easy to use, idiomatic Go.
So what is the purpose of binding? Currently, it's to populate an instance of a type with values and validate the result. I think that's a good overall purpose. It also happens to provide form and multipart deserializers and data validation, along with interfaces to facilitate all that. Also very useful. But it also employs third-party serializers like encoding/json for JSON payloads. And it could support others.
Issue #24 raises the question of limiting binding to net/http. Why not open it to the more general io.Reader? We could have a wrapper function to make net/http convenient, but at its core, relying on io.Reader seems more useful. While we're at it, we could clean up and compartmentalize the error handling/validation APIs some more.
These are some things I'm kicking around in my head. Discussion is encouraged, and I invite users of the package to add your feedback.