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

Apply Custom Value Setters to custom struct types #106

Open
byted opened this issue Oct 27, 2022 · 0 comments
Open

Apply Custom Value Setters to custom struct types #106

byted opened this issue Oct 27, 2022 · 0 comments

Comments

@byted
Copy link

byted commented Oct 27, 2022

I realized that a SetValue() defined on a custom struct type is never called. Insted, the struct is flattened. This prevents me from parsing e.g., a yaml string from an ENV variable:

type Config struct {
	Complex ComplexYamlConfig `env:"COMPLEX_CONFIG"`
}

type ComplexYamlConfig struct {
	Left  string `yaml:"myProp"`
}

func (c *ComplexYamlConfig) SetValue(s string) error {
        // will never be called by cleanenv
	return yaml.Unmarshal([]byte(s), c)
}

Is this something that can be added? Or is there a different way of achieving the same thing?

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

1 participant