add GetEnvDefault
This commit is contained in:
parent
906d43322e
commit
e21dbcc61b
11
str.go
11
str.go
@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -104,6 +105,7 @@ func JsonstrToStrMap(jsonstr string) (m map[string]string) {
|
||||
}
|
||||
|
||||
// string to string map to string
|
||||
//
|
||||
// example: "K1:V1;K2:V2"
|
||||
// => {K1:V1, K2:V2}
|
||||
func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
||||
@ -115,3 +117,12 @@ func StringToStrMap(str string, sep1, sep2 string) (m map[string]string) {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// get os env with default
|
||||
func GetEnvDefault(key, defval string) string {
|
||||
if val, ok := os.LookupEnv(key); ok {
|
||||
return val
|
||||
} else {
|
||||
return defval
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user