diff --git a/hack/.golint_failures b/hack/.golint_failures index 33a49b14aa7..d768862ee26 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -230,7 +230,6 @@ pkg/serviceaccount pkg/ssh pkg/util/config pkg/util/ebtables -pkg/util/env pkg/util/goroutinemap/exponentialbackoff pkg/util/iptables pkg/util/iptables/testing diff --git a/pkg/util/env/env.go b/pkg/util/env/env.go index dee544f7c66..6879c5052b1 100644 --- a/pkg/util/env/env.go +++ b/pkg/util/env/env.go @@ -21,6 +21,8 @@ import ( "strconv" ) +// GetEnvAsStringOrFallback returns the env variable for the given key +// and falls back to the given defaultValue if not set func GetEnvAsStringOrFallback(key, defaultValue string) string { if v := os.Getenv(key); v != "" { return v @@ -28,6 +30,8 @@ func GetEnvAsStringOrFallback(key, defaultValue string) string { return defaultValue } +// GetEnvAsIntOrFallback returns the env variable (parsed as integer) for +// the given key and falls back to the given defaultValue if not set func GetEnvAsIntOrFallback(key string, defaultValue int) (int, error) { if v := os.Getenv(key); v != "" { value, err := strconv.Atoi(v) @@ -39,6 +43,8 @@ func GetEnvAsIntOrFallback(key string, defaultValue int) (int, error) { return defaultValue, nil } +// GetEnvAsFloat64OrFallback returns the env variable (parsed as float64) for +// the given key and falls back to the given defaultValue if not set func GetEnvAsFloat64OrFallback(key string, defaultValue float64) (float64, error) { if v := os.Getenv(key); v != "" { value, err := strconv.ParseFloat(v, 64)