Skip to content
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

custom Decoder is not called on input struct, it is only called on fields within a struct #60

Closed
twmb opened this issue Jul 13, 2022 · 3 comments

Comments

@twmb
Copy link

twmb commented Jul 13, 2022

If I pass a type that implements Decoder to Process, the EnvDecode function is not called. However, if a field within my input struct implements Decoder, then EnvDecode is called.

In https://go.dev/play/p/wforR2YscKr, I would expect CALLED to be printed after both 1 and 2. It is only printed after 2.

@sethvargo
Copy link
Owner

Hi @twmb

Thank you for opening an issue. I'm not sure how this makes sense. The custom decoder accepts the environment variable as an input to the function. In your example, there's no place to define which environment variable to pass to the custom decode function.

What problem are you trying to solve?

@twmb
Copy link
Author

twmb commented Jul 13, 2022

I think I see what you mean: it's impossible to define a key for the top level input.

What's odd is that EnvDecode is being called at all given there can be no key in the first example, and there is no key in the second example. This is an artifact of the investigation into #61

@sethvargo
Copy link
Owner

I think I see what you mean: it's impossible to define a key for the top level input.

Right - you have to wrap it in another struct unfortunately. That's just a limitation of Go.

What's odd is that EnvDecode is being called at all given there can be no key in the first example, and there is no key in the second example. This is an artifact of the investigation into #61

Yea that makes sense. I'm going to close this out and we'll figure out a solution to #61.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants