Skip to content

Commit

Permalink
GetEnvWithDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
effoeffi committed Mar 20, 2024
1 parent 3dd9a82 commit 7e78b93
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions env/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package env

import (
"os"
"strconv"
)

func GetEnvWithDefault(key, defaultValue string) string {

res, exists := os.LookupEnv(key)
if !exists {
return defaultValue
}

return res
}

func GetEnvIntWithDefault(key string, defaultValue int) int {

value, exists := os.LookupEnv(key)
if !exists {
return defaultValue
}

res, err := strconv.Atoi(value)
if err != nil {
return defaultValue
}

return res
}

0 comments on commit 7e78b93

Please sign in to comment.