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.
40 lines
604 B
40 lines
604 B
package goenv
|
|
|
|
import (
|
|
"go.dtapp.net/library/gostring"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func GetEnvDefault(key, defVal string) string {
|
|
val, ok := os.LookupEnv(key)
|
|
if ok {
|
|
return val
|
|
}
|
|
return defVal
|
|
}
|
|
|
|
func GetEnvDefaultInt(key string, defVal int) int {
|
|
val, ok := os.LookupEnv(key)
|
|
if ok {
|
|
return gostring.ToInt(val)
|
|
}
|
|
return defVal
|
|
}
|
|
|
|
func GetEnvs(key string) string {
|
|
envs := os.Environ()
|
|
for _, e := range envs {
|
|
parts := strings.SplitN(e, "=", 2)
|
|
if len(parts) != 2 {
|
|
continue
|
|
} else {
|
|
println(parts[0], parts[1])
|
|
if parts[0] == key {
|
|
return parts[1]
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|