Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybeecave committed Apr 25, 2020
1 parent b0205c4 commit 61f6ab2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/nerdynz/trove

go 1.12

require github.com/joho/godotenv v1.3.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
8 changes: 8 additions & 0 deletions trove.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,21 @@ func (s *Settings) GetBool(setting string) bool {
return val
}

// Get gets and caches an ENV setting. theDefault will be used if setting is blank and is optional
func (s *Settings) Get(setting string) string {
return s.GetWithDefault(setting, "")
}

func (s *Settings) GetWithDefault(setting string, theDefault string) string {
val, ok := s.strings[setting]
if !ok {
s.sLock.Lock() // map is shared across the whole application, so it needs to be
defer s.sLock.Unlock()

newVal := os.Getenv(setting)
if newVal == "" && theDefault != "" {
return theDefault
}
s.strings[setting] = newVal
val = newVal
}
Expand Down

0 comments on commit 61f6ab2

Please sign in to comment.