mirror of
https://github.com/astaxie/beego.git
synced 2025-07-06 16:10:19 +00:00
remove interfaceToStr function to package config
This commit is contained in:
@ -119,6 +119,7 @@ func Getenv(env interface{}) (string, bool) {
|
||||
|
||||
// Onley support string key.
|
||||
if key, ok := env.(string); ok {
|
||||
|
||||
if envKey := strings.TrimPrefix(key, envKeySign); envKey != key {
|
||||
return os.Getenv(envKey), true
|
||||
}
|
||||
@ -126,6 +127,36 @@ func Getenv(env interface{}) (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// ConvertToStringMap convert interface to string config value only for map[string]interface{} config info.
|
||||
func ConvertToStringMap(m map[string]interface{}) map[string]string {
|
||||
items := make(map[string]string, len(m))
|
||||
if m == nil || len(m) == 0 {
|
||||
return items
|
||||
}
|
||||
|
||||
var s string
|
||||
for k, v := range m {
|
||||
s = ""
|
||||
if v == nil {
|
||||
s = ""
|
||||
} else if str, ok := v.(string); ok {
|
||||
s = str
|
||||
} else if m, ok := v.(map[string]interface{}); ok {
|
||||
s = fmt.Sprintf("%+v", ConvertToStringMap(m))
|
||||
} else {
|
||||
s = fmt.Sprintf("%+v", v)
|
||||
}
|
||||
|
||||
if len(s) > 0 {
|
||||
if env, ok := Getenv(s); ok {
|
||||
s = env
|
||||
}
|
||||
}
|
||||
items[k] = s
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
// ParseBool returns the boolean value represented by the string.
|
||||
//
|
||||
// It accepts 1, 1.0, t, T, TRUE, true, True, YES, yes, Yes,Y, y, ON, on, On,
|
||||
|
Reference in New Issue
Block a user