-
Notifications
You must be signed in to change notification settings - Fork 23
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 support for .env files #3
Conversation
envy.go
Outdated
|
||
// It exists and we have permission. Load it | ||
err = godotenv.Overload(file) | ||
Reload() |
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.
The call to Reload
should probably get moved to after the err
check. There's no point in reloading if there was an error.
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.
You are totally right. It has been modified now :)
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.
A couple more changes, sorry. Also, I wonder if it makes sense to try and load .env.XX
based on the GO_ENV
ENV var. Buffalo uses GO_ENV
to switch to production
, development
, etc... it would be nice if these files were "auto-loaded", if they exist.
envy.go
Outdated
// If no files received, load the default one | ||
if len(files) == 0 { | ||
err := godotenv.Overload() | ||
Reload() |
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.
There's no error check here. Can we add one:
if err := godotenv.Overload(); err == nil {
Reload()
}
return nil
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.
Then we wouldn't be returning the error.
We could change it to
err := godotenv.Overload()
if err == nil {
Reload()
}
return err
to avoid the unnecessary Reload
call (and indeed returning the error)
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.
that seems so weird, but yeah, let's do that.
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.
Changed in 73986d1
envy.go
Outdated
for _, file := range files { | ||
|
||
// Check if it exists or we can access | ||
_, err := os.Stat(file) |
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.
can we collapse these error checks in this for
block to use the if err := dosomething; err != nil
style syntax?
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.
Changed in 094661c
envy.go
Outdated
// If no files received, load the default one | ||
if len(files) == 0 { | ||
err := godotenv.Overload() | ||
Reload() |
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.
that seems so weird, but yeah, let's do that.
That change would be added in the Buffalo project, not here. But first I needed to add support for dotenv files in envy, and then I would be able to add this "autoload" to buffalo. Note that it wouldn't be useful in things such as: const PORT = envy.Get("PORT", "8080") As this kind of values are resolved before any other call has been made (including the envy.Reload one). |
thanks! |
Fixes #2