-
Notifications
You must be signed in to change notification settings - Fork 407
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
.env: no such file or directory #213
Comments
I just tried // imports
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
} and then ran Could you provide some more details? |
try this :
|
It looks like this is as stale issue that can be closed? cc/ @chihao10711 |
so my expectation prior to reading the code would be that it would look for .env files in the list you gave it, loading the ones that exist, so that you could give it a list and it would load what it found. The reality is that it stops at the first missing file, due to a file not found error being treated as a hard error. This is a design decision, but is it what the user wants? I ended up writing a Basically the Load() function here works like the ruby Load!() which I wouldn't expect given the project goal. It would be a breaking API change for the folks who've installed and now expect this behavior though, so maybe you just want to add a function to trim down the file list to only existing ones which will then effectively make this work like Load on the result of that function. |
@beiriannydd Even I have similar requirements to try loading all files found and return an error at the end if any errors occur along with the ability to look at the root git directory, also at the go mod directory level. Probably if you have similar requirements, you can utilise this |
When I use
go run
it works well. However, when usinggo build
couldn't be found .env.Please help me with this?
The text was updated successfully, but these errors were encountered: