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

Document how the env tag works when using structs-in-structs #38

Open
sweepies opened this issue Mar 2, 2021 · 0 comments
Open

Document how the env tag works when using structs-in-structs #38

sweepies opened this issue Mar 2, 2021 · 0 comments

Comments

@sweepies
Copy link

sweepies commented Mar 2, 2021

Suppose I have the following code:

type Config struct {
	S3 S3Configuration
}

type S3Configuration struct {
	Endpoint string `env:"S3_ENDPOINT"`
	Region   string `env:"S3_REGION"`
	Bucket   string `env:"S3_BUCKET"`
}

The env tags in the S3Configuration struct won't work properly because there is no env tag specified on the S3 field in the Config struct. What you have to do instead is specify an env tag with an S3 namespace and then remove the S3_ prefix from the sub-struct, like so:

type Config struct {
	S3 S3Configuration `env:"S3"
}

type S3Configuration struct {
	Endpoint string `env:"ENDPOINT"`
	Region   string `env:"REGION"`
	Bucket   string `env:"BUCKET"`
}

This was unintuitive to me and caused some headache, so I feel it would help if it was documented 😅

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