imported env module
This commit is contained in:
23
env/duration.go
vendored
Normal file
23
env/duration.go
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Get an environment variable as a time.Duration, specifying a default value if its
|
||||
// not set or can't be parsed properly
|
||||
func Duration(key string, defaultValue time.Duration) time.Duration {
|
||||
val, exists := os.LookupEnv(key)
|
||||
if !exists {
|
||||
return time.Duration(defaultValue)
|
||||
}
|
||||
|
||||
intVal, err := strconv.Atoi(val)
|
||||
if err != nil {
|
||||
return time.Duration(defaultValue)
|
||||
}
|
||||
return time.Duration(intVal)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user