When I try to read the .env file it does not work without using the absolute path.
func init() {
err := godotenv.Load(".env") //<--fails
//err := godotenv.Load("./.env") //<--fails
//err := godotenv.Load("/home/peter/Documents/tests/configuration/.env") //<--works
if err != nil {
panic(err)
}
Config = GetConfig()
}
I get panic: open .env: no such file or directory
But the file is there
$ ls -a
. .. config.go .env
Any clue?
CodePudding user response:
A potential problem is that the directory you are running the executable from is different than the directory of which the .env file is located. Could you verify this?