Skip to content

Commit 9417b80

Browse files
authored
Merge pull request #14 from jeijei4/patch-1
Fix: Incomplete value if it contains the = symbol
2 parents 2c48868 + 0bbb8c8 commit 9417b80

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/infrastructure/env.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package infrastructure
33
import (
44
"bufio"
55
"os"
6+
"regexp"
67
"strings"
78

89
"github.com/bmf-san/go-clean-architecture-web-application-boilerplate/app/usecases"
@@ -28,7 +29,12 @@ func Load(logger usecases.Logger) {
2829
}
2930

3031
for _, l := range lines {
31-
pair := strings.Split(l, "=")
32-
os.Setenv(pair[0], pair[1])
32+
pair := regexp.MustCompile(`=`).Split(l, 2)
33+
34+
if len(pair) > 1 {
35+
os.Setenv(strings.TrimSpace(pair[0]), strings.TrimSpace(pair[1]))
36+
} else {
37+
logger.LogError(".env file. Wrong format for " + pair[0])
38+
}
3339
}
3440
}

0 commit comments

Comments
 (0)