feat(httputil): add Bind/BindEmpty request binding from path and query; v1.6.0
Bind and BindEmpty fill Req from path/query/json struct tags and validate once, extending the typed decode->validate->call->encode pipeline to routes with identifiers and filters. Conversion via builtins + encoding.TextUnmarshaler (uuid.UUID, time.Time); malformed value -> 400 naming the parameter; default: applies only when absent; repeated query -> slice; mis-tagged struct panics at wiring. Purely additive; existing adapters unchanged. Coordinated lockstep v1.6.0.
This commit is contained in:
@@ -6,7 +6,13 @@ var _ http.Handler = HandlerFunc(nil)
|
||||
|
||||
// HandlerFunc is an http.Handler that returns an error.
|
||||
// On non-nil error the error is mapped to the appropriate HTTP response via [Error].
|
||||
// Use for manual handlers that need path parameters or custom status codes.
|
||||
//
|
||||
// Use it for genuinely custom responses — streaming, file downloads, non-JSON
|
||||
// content types — where the typed adapters do not fit. It is no longer the answer
|
||||
// for path or query parameters: [Bind] and [BindEmpty] fill those from struct tags
|
||||
// with the same decode → validate → encode guarantees, and a custom success status
|
||||
// is set with [WithStatus]. Reaching for HandlerFunc to read a parameter is the one
|
||||
// path by which a handler reaches production without validation running.
|
||||
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
// ServeHTTP implements http.Handler.
|
||||
|
||||
Reference in New Issue
Block a user