refactor to mautrix 0.17.x; update deps
This commit is contained in:
26
vendor/gitlab.com/etke.cc/go/env/env.go
generated
vendored
26
vendor/gitlab.com/etke.cc/go/env/env.go
generated
vendored
@@ -14,26 +14,36 @@ func SetPrefix(prefix string) {
|
||||
}
|
||||
|
||||
// String returns string vars
|
||||
func String(shortkey string, defaultValue string) string {
|
||||
func String(shortkey string, defaultValue ...string) string {
|
||||
var dv string
|
||||
if len(defaultValue) > 0 {
|
||||
dv = defaultValue[0]
|
||||
}
|
||||
|
||||
key := strings.ToUpper(envprefix + "_" + strings.ReplaceAll(shortkey, ".", "_"))
|
||||
value := strings.TrimSpace(os.Getenv(key))
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
return dv
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
// Int returns int vars
|
||||
func Int(shortkey string, defaultValue int) int {
|
||||
str := String(shortkey, "")
|
||||
func Int(shortkey string, defaultValue ...int) int {
|
||||
var dv int
|
||||
if len(defaultValue) > 0 {
|
||||
dv = defaultValue[0]
|
||||
}
|
||||
|
||||
str := String(shortkey)
|
||||
if str == "" {
|
||||
return defaultValue
|
||||
return dv
|
||||
}
|
||||
|
||||
val, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
return dv
|
||||
}
|
||||
|
||||
return val
|
||||
@@ -41,7 +51,7 @@ func Int(shortkey string, defaultValue int) int {
|
||||
|
||||
// Bool returns boolean vars (1, true, yes)
|
||||
func Bool(shortkey string) bool {
|
||||
str := strings.ToLower(String(shortkey, ""))
|
||||
str := strings.ToLower(String(shortkey))
|
||||
if str == "" {
|
||||
return false
|
||||
}
|
||||
@@ -50,7 +60,7 @@ func Bool(shortkey string) bool {
|
||||
|
||||
// Slice returns slice from space-separated strings, eg: export VAR="one two three" => []string{"one", "two", "three"}
|
||||
func Slice(shortkey string) []string {
|
||||
str := String(shortkey, "")
|
||||
str := String(shortkey)
|
||||
if str == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user