add vendoring
This commit is contained in:
59
vendor/gitlab.com/etke.cc/go/env/env.go
generated
vendored
Normal file
59
vendor/gitlab.com/etke.cc/go/env/env.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var envprefix string
|
||||
|
||||
// SetPrefix sets prefix for all env vars
|
||||
func SetPrefix(prefix string) {
|
||||
envprefix = prefix
|
||||
}
|
||||
|
||||
// String returns string vars
|
||||
func String(shortkey string, defaultValue string) string {
|
||||
key := strings.ToUpper(envprefix + "_" + strings.ReplaceAll(shortkey, ".", "_"))
|
||||
value := strings.TrimSpace(os.Getenv(key))
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
// Int returns int vars
|
||||
func Int(shortkey string, defaultValue int) int {
|
||||
str := String(shortkey, "")
|
||||
if str == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
val, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
// Bool returns boolean vars (1, true, yes)
|
||||
func Bool(shortkey string) bool {
|
||||
str := strings.ToLower(String(shortkey, ""))
|
||||
if str == "" {
|
||||
return false
|
||||
}
|
||||
return (str == "1" || str == "true" || str == "yes")
|
||||
}
|
||||
|
||||
// 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, "")
|
||||
if str == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return strings.Split(str, " ")
|
||||
}
|
||||
Reference in New Issue
Block a user