You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
895 B
43 lines
895 B
package util
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const prefix = "CD_"
|
|
|
|
// EnvStr returns the value of the environment variable named by the key.
|
|
func EnvStr(key, defaultValue string) string {
|
|
if value, exist := os.LookupEnv(prefix + key); exist {
|
|
return value
|
|
}
|
|
|
|
return defaultValue
|
|
}
|
|
|
|
// EnvInt returns the value of the environment variable named by the key.
|
|
func EnvInt(key string, defaultValue int) int {
|
|
if value, exist := os.LookupEnv(prefix + key); exist {
|
|
number, err := strconv.Atoi(value)
|
|
if err != nil {
|
|
// I think that we should log this error
|
|
return defaultValue
|
|
}
|
|
|
|
return number
|
|
}
|
|
|
|
return defaultValue
|
|
}
|
|
|
|
// EnvArr returns the value of the environment variable named by the key.
|
|
func EnvArr(key string, defaultValue []string) []string {
|
|
if value, exist := os.LookupEnv(prefix + key); exist {
|
|
return strings.Split(value, ",")
|
|
}
|
|
|
|
return defaultValue
|
|
}
|