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

Feature Request: non-global directives #109

Open shawalli opened 4 months ago

shawalli commented 4 months ago

Summary

I'd like to be able to register directives against an instance and then perform encoding and decoding against that instance.

Reason

I have an API (i.e. "API A") that also calls another API ("API B"). API B provides structs with httpin struct tags via an importable package. API A also provides structs with httpin tags. The structs in API A and API B have different needs and therefore different directives that need to be registered. However, with the current design, all directives are registered against the global namespace.

Proposed Solution

The Core struct seems perfectly set up to do this. Each instance could register a new namespace, or have a way of localizing the registrations inside its own scope.