Skip to content

v0.15.0

Compare
Choose a tag to compare
@ggicci ggicci released this 31 Dec 00:29
· 29 commits to main since this release

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.