-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better Generic Support For ISCs #1706
base: v2-maint
Are you sure you want to change the base?
Conversation
098c58a
to
be6cc47
Compare
- Allow generics to be set as their Set() string in the config - Allow converting internal ISC types to Generics when: - The data used to define the Generic can be expressed in JSON - The target Generic implements `FromJson([]byte) error` - The source ISC implements `Json(name string) ([]byte, error)` - Update existing ISC implementations to also implement `Json(name string) ([]byte, error)` And of course there are tests for the new features.
be6cc47
to
f760a89
Compare
@danhunsaker v2 is only in maintenance mode. You do realise that v3/main branch has support for generics already ? |
v3 isn't released/usable/documented yet. I imagine this will need to be forward-ported to v3 as well at some point, but until it's actually released, I can't use it in my own apps. Thus targeting v2 for the moment. Plus, this PR is specifically for handling of |
@danhunsaker Thank you again for your patience! I've got much the same feedback as in #1702. How would you like to handle next steps? |
Hey, @danhunsaker. Thank you for this PR. Some merge conflicts showed up, and as Dan explained above, we're very reluctant to accept new features into v2 (much smaller PRs were getting rejected because of this policy). Now, I'm a new maintainer and new to this codebase, so I'm not yet sure if it makes sense to re-target this PR against https://github.com/urfave/cli-altsrc. I'm just trying to see what's the state that this PR is in. I don't like if they live for long, because they rot. Again, thanks for all the work. |
Extending code surface to +416 new lines for a maintenance project is also a security risk. |
What type of PR is this?
What this PR does / why we need it:
FromJson([]byte) error
Json(name string) ([]byte, error)
Json(name string) ([]byte, error)
And of course, there are tests for the new features.
As to why, the internal ISCs don't actually support Generics, as they don't know about these types to be able to deserialize into them directly. Proper support requires the ability to coerce the intermediate types into a Generic type. This can be done one of two ways - by using a string equivalent as you would on the CLI, or by implementing methods that can handle a JSON intermediate version on the Generic itself.
Given:
The following examples are equivalent for the sample
HostPort
type added in this PR to thealtsrc
tests:Third-party code that implements its own InputSourceContext may already support storing Generics in its internal structure, in which case the new code paths won't be hit, rendering full BC.
Testing
Tests were updated in the code to cover the new scenarios.
Release Notes