Skip to content

Commit

Permalink
env file loading fix
Browse files Browse the repository at this point in the history
  • Loading branch information
speier committed Nov 22, 2024
1 parent 499e5ac commit e4bc70c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.4.1
VERSION=v0.4.2

release:
@git tag -a ${VERSION} -m "Release ${VERSION}" && git push origin ${VERSION}
Expand Down
2 changes: 1 addition & 1 deletion examples/service_a/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func main() {
fmt.Println("service #1 running")
fmt.Println(os.Getenv("TEST"))
fmt.Println("env TEST:", os.Getenv("TEST"))

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
Expand Down
21 changes: 14 additions & 7 deletions internal/support/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ func Environ(dir string, env ...string) []string {
func dotenvFiles(dir string) (res []string) {
filenames := []string{dir + "/" + defenv, dir + "/" + usrenv}

envMap, err := godotenv.Read(filenames...)
if err != nil {
return
}

for k, v := range envMap {
res = append(res, k+"="+v)
for _, filename := range filenames {
src, err := os.ReadFile(filename)
if err != nil {
return
}

envMap, err := godotenv.UnmarshalBytes(src)
if err != nil {
return
}

for k, v := range envMap {
res = append(res, k+"="+v)
}
}

return
Expand Down

0 comments on commit e4bc70c

Please sign in to comment.