Skip to content

Commit

Permalink
Fix: Incomplete value if it contains the = symbol
Browse files Browse the repository at this point in the history
Error: if the value contains the = symbol then delete it.
Solution: Capture only the first = symbol.
  • Loading branch information
jeijei4 authored Dec 29, 2022
1 parent 2c48868 commit 0bbb8c8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/infrastructure/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package infrastructure
import (
"bufio"
"os"
"regexp"
"strings"

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

for _, l := range lines {
pair := strings.Split(l, "=")
os.Setenv(pair[0], pair[1])
pair := regexp.MustCompile(`=`).Split(l, 2)

if len(pair) > 1 {
os.Setenv(strings.TrimSpace(pair[0]), strings.TrimSpace(pair[1]))
} else {
logger.LogError(".env file. Wrong format for " + pair[0])
}
}
}

0 comments on commit 0bbb8c8

Please sign in to comment.