Releases: ggicci/httpin
v0.20.2
v0.20.1
v0.20.0
New Features
httpin now supports encoding and decoding path variables when using the native net/http
package for routing.
This feature was brough in #113 by @chriss-de, thanks :)
import httpin_integration "github.com/ggicci/httpin/integration"
func init() {
httpin_integration.UseHttpPathVariable("path")
}
Breaking Changes
The API UseEchoPathRouter(e)
was removed due to unnecessary abstraction, please migrate to use UseEchoPathRouter("path", e)
instead.
v0.19.0
New Feature
Introduced a new directive omitempty
, which works on encoding a Go struct to an http.Request. Just think of how omitempty
works in encoding/json
package. Here in httpin, omitempty
will omit adding keys to Query, Form, Header when the corresponding value is empty. See reflect.Value.IsZero
for more details about how we judge an empty value.
Thanks to @alecsammon who made this feature availalbe for all httpin users.
v0.18.1
v0.18.0
Fixes #101
Breaking Change and Migration Guide
func DecodeTo(req *http.Request, input any, opts ...core.Option) error
API has been renamed to DecodeTo
, it will populate the given input
value instead of creating a new instance internally.
How to migrate to v0.18.0?
Since we haven't changed the signature of this function, we can migrate by replacing httpin.Decode
with httpin.DecodeTo
in your codebase.
New API
Added new func Decode[T any](req *http.Request, opts ...core.Option) (*T, error)
API, example usage:
type AddUserInput struct {
Username string `in:"form=username"`
}
if input, err := httpin.Decode[AddUserInput](req); err != nil { ... }
// input.Username
v0.17.0
v0.16.0
API Changes
Added optional parameter opts ...core.Option
to the following APIs:
httpin.Decode(req *http.Request, input any) error
->httpin.Decode(req *http.Request, input any, opts ...core.Option) error
httpin.NewRequest(method, url string, input any) (*http.Request, error)
->httpin.NewRequest(method, url string, input any, opts ...core.Option) (*http.Request, error)
httpin.NewRequestWithContext(ctx context.Context, method, url string, input any) (*http.Request, error)
->httpin.NewRequestWithContext(ctx context.Context, method, url string, input any, opts ...core.Option) (*http.Request, error)
Added a new variable httpin.Option
where is a collection of the options.
v0.15.3
v0.15.2
Register the path directive by default, but it only supports encoding function. For a complete path directive, users still need to use the integration
subpackage:
import httpin_integration "github.com/ggicci/httpin/integration"
func init() {
httpin_integration.UseGochiURLParam("gochi", chi.URLParam)
}