Skip to content

Releases: ggicci/httpin

v0.19.0

20 May 23:00
eed0621
Compare
Choose a tag to compare

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.

#107

Thanks to @alecsammon who made this feature availalbe for all httpin users.

v0.18.1

30 Apr 03:51
6a628af
Compare
Choose a tag to compare

Remove indirect dependency to echo by moving the testing code under _test package.

v0.18.0

20 Apr 23:12
31c7322
Compare
Choose a tag to compare

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

15 Mar 05:51
c8657ee
Compare
Choose a tag to compare

#99 Added echo integration, register a "path" directive that can work with echo router.

import httpin_integration "github.com/ggicci/httpin/integration"

func init() {
    e := echo.New()
    httpin_integration.UseEchoRouter("path", e)

    // or
    httpin_integration.UseEchoPathRouter(e)
}

Thanks

@sorenmat

v0.16.0

28 Jan 23:47
Compare
Choose a tag to compare

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

14 Jan 18:36
5dca4c8
Compare
Choose a tag to compare

Fixed #88 - make httpin able to stream uploading large files.

Thanks @excavador

v0.15.2

31 Dec 07:08
Compare
Choose a tag to compare

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)
}

v0.15.1

31 Dec 03:52
Compare
Choose a tag to compare

Fix POST form data bug.

v0.15.0

31 Dec 00:29
Compare
Choose a tag to compare

New Features

  1. Include encoding functionality to this package. From now on, httpin doesn't only support decoding an HTTP request to a Go struct, it supports encoding a Go struct to an HTTP request as well. Simply call httpin.NewRequest method. Because all the builtin directives now support encoding functions.
  2. Introduced a new directive named nonzero. Which is used to cover/correct miss-use of the required directive, use nonzero instead of required to ensure that the field not be a zero/empty value.
  3. For custom struct types, you don't need to register it to httpin any more, as long as you implement the Stringable interface.

Breaking Changes

  1. Less APIs are exposed under package httpin. I hope the list will be limited to the following, which I would like to keep in the first stable release (v1.0.0):
    • httpin.New: creates a core.Core instance;
    • httpin.NewInput: creates a HTTP middleware;
    • httpin.Input: the context key to retrieve the decoded struct instance that was injected to http.Request.Context by httpin;
    • httpin.Decode: decode an HTTP request to a struct instance;
    • httpin.NewRequest: encode a struct instance to an HTTP request;
    • httpin.NewRequestWithContext: call httpin.NewRequest with a context.Context;
    • httpin.File: the type for manipulating file uploading in httpin;
    • httpin.UploadFile: upload file by filename;
    • httpin.UploadStream: upload file by stream.
  2. APIs to integrate with third-party packages are moved to the integration subpackage:
    • httpin.UseGochiURLParam: registers a path directive for the gochi routing package, use httpin_integration.UseGochiURLParam instead;
    • httpin.UseGorillaMux: registers a path directive for the gorilla/mux routing package, use httpin_integration.UseGorillaMux instead;
  3. All the other APIs used to extend http functions are moved to core subpackage and many of them have been changed because the newly introduced encoding ability:
    • httpin.RegisterValueTypeDecoder[T]: use httpin_core.RegisterCoder instead;
    • httpin.RegisterNamedDecoder[T]: use httpin_core.RegisterNamedCoder[T] instead;
    • httpin.RegisterFileTypeDecoder[T]: use httpin_core.RegisterFileCoder[T] instead;
    • httpin.RegisterBodyDecoder: use httpin_core.RegisterBodyFormat instead;
    • httpin.ReplaceDefaultErrorHandler: use httpin_core.RegisterErrorHandler instead;
    • DEPRECATED httpin.ReplaceValueTypeDecoder[T]: use httpin_core.RegisterCoder instead;
    • DEPRECATED httpin.ReplaceNamedDecoder[T]: use httpin_core.RegisterNamedCoder[T] instead;
    • DEPRECATED httpin.ReplaceFileTypeDecoder[T]: use httpin_core.RegisterFileCoder[T] instead;
    • DEPRECATED httpin.ReplaceBodyDecoder: use httpin_core.RegisterBodyFormat instead;
  4. httpin no longer run directives defined in nested structs, you have to either use httpin_core.WithNestedDirectivesEnabled option or enable it manually with httpin_core.EnableNestedDirectives.

v0.14.2

29 Oct 18:38
5317ab1
Compare
Choose a tag to compare

Bug Fixes

  • #77 Decode parameter struct with default values only works the first time