using this library https://github.com/joho/godotenv
err := godotenv.Load("/app/cmd/app/db.env") // if false, load the envs.
if err != nil {
dir, _ := os.Getwd()
log.Printf("Currently on the directory> %s", dir)
log.Fatal("Error loading .env file", err)
}
so uh. here is a code snippet.
be ready, this is stupid.
COPY --from=modules /go/pkg /go/pkg
COPY . /app
WORKDIR /app
RUN ls -la /app/cmd/app
when I run this Dockerfile while building the docker-compose,
RUN ls -la /app/cmd/app
prints
drwxr-xr-x 5 root root 4096 Nov 22 19:20 .
drwxr-xr-x 3 root root 4096 Nov 22 18:05 ..
-rw-r--r-- 1 root root 12111346 Nov 22 18:05 app
drwxr-xr-x 3 root root 4096 Nov 22 18:05 data
-rw-r--r-- 1 root root 137 Nov 22 19:17 db.env
drwxr-xr-x 4 root root 4096 Nov 22 18:05 logs
-rw-r--r-- 1 root root 4374 Nov 22 18:05 main.go
drwxr-xr-x 2 root root 4096 Nov 22 18:05 textfiles
so db.env is there! so this should work right! right?
err := godotenv.Load("/app/cmd/app/db.env") // if false, load the envs.
no it doesnt. it panics at loading env. with an error of ```go
gmud | 2022/11/22 19:41:37 Currently on the directory> /
gmud | 2022/11/22 19:41:37 Error loading .env fileopen /app/cmd/app/db.env: not a directory