ggicci / httpin

🍡 HTTP Input for Go - HTTP Request from/to Go Struct (Bi-directional Data Binding between Go Struct and http.Request)
https://ggicci.github.io/httpin/
MIT License
315 stars 23 forks source link

Feat/decode api update #105

Closed ggicci closed 5 months ago

ggicci commented 5 months ago

Breaking Change

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, updates #101

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
codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.78%. Comparing base (c8657ee) to head (e72964c).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #105 +/- ## ========================================== + Coverage 90.67% 90.78% +0.10% ========================================== Files 34 34 Lines 1512 1530 +18 ========================================== + Hits 1371 1389 +18 Misses 97 97 Partials 44 44 ``` | [Flag](https://app.codecov.io/gh/ggicci/httpin/pull/105/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ggicci) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/ggicci/httpin/pull/105/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ggicci) | `90.78% <100.00%> (+0.10%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ggicci#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.