-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Add expand option to support variable expansion #57
Conversation
There were the following issues with this Pull Request
You may need to change the commit messages to comply with the repository contributing guidelines. 🤖 This comment was generated by commitlint[bot]. Please report issues here. Happy coding! |
env_test.go
Outdated
ExpandKey string `env:"EXPAND_KEY"` | ||
CompoundKey string `env:"HOST_PORT,expand"` | ||
} | ||
os.Setenv("HOST", "localhost") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to rely on envDefault
for HOST
and PORT
but the package does not call os.Setenv
when parsing the config.
cd5befe
to
ebc7b7d
Compare
@jheth For the sake of readability and usability, I suggest being able to specify the expand option like this,
instead of
If you could re implement it that way, I am okay with it be merged. |
We can probably use https://golang.org/pkg/os/#ExpandEnv instead of writing our own function... |
ebc7b7d
to
3108c2b
Compare
env.go
Outdated
@@ -114,6 +114,11 @@ func get(field reflect.StructField) (string, error) { | |||
defaultValue := field.Tag.Get("envDefault") | |||
val = getOr(key, defaultValue) | |||
|
|||
expandVar := field.Tag.Get("ExpandVar") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be envExpand
to be in the same pattern of the other options.
Adding it to the readme as well would be nice =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I've updated and simplified the overall change once again.
3108c2b
to
998eb22
Compare
thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good thanks for the contribution
Add expand option to support variable expansion
We are wanting to reference environment variables from existing variables. I've added this as an
expand
option but could be part of the default behavior if that's desired. This will look for the${VAR}
pattern and replace with the appropriate variable if found.