new helper method
This commit is contained in:
parent
ffbd38f69a
commit
c1c0e46184
1 changed files with 12 additions and 3 deletions
|
|
@ -27,13 +27,22 @@ func getEnvSeconds(key string, fallback int) time.Duration {
|
|||
return time.Duration(fallback) * time.Second
|
||||
}
|
||||
|
||||
func getEnvInt(key string, fallback int) int {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
num, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return num
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func getEnvUint(key string, fallback uint) uint {
|
||||
var def uint = 100
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
num, err := strconv.ParseUint(value, 10, 64)
|
||||
if err != nil {
|
||||
log.Printf("Error converting %v to uint, using default value - %v", key, def)
|
||||
return def
|
||||
return fallback
|
||||
}
|
||||
return uint(num)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue