自定义配置参数不区分大小写
This commit is contained in:
parent
5a67d8f073
commit
22dc0a767a
|
@ -2,6 +2,7 @@ package common
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"mongo.games.com/goserver/core"
|
||||
)
|
||||
|
@ -53,6 +54,13 @@ func (this *CustomConfiguration) GetString(key string) string {
|
|||
return str
|
||||
}
|
||||
}
|
||||
|
||||
if v, exist := (*this)[strings.ToLower(key)]; exist {
|
||||
if str, ok := v.(string); ok {
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -67,6 +75,18 @@ func (this *CustomConfiguration) GetStrings(key string) (strs []string) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
if v, exist := (*this)[strings.ToLower(key)]; exist {
|
||||
if vals, ok := v.([]interface{}); ok {
|
||||
for _, s := range vals {
|
||||
if str, ok := s.(string); ok {
|
||||
strs = append(strs, str)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -86,6 +106,23 @@ func (this *CustomConfiguration) GetCustomCfgs(key string) (strs []*CustomConfig
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
if v, exist := (*this)[strings.ToLower(key)]; exist {
|
||||
if vals, ok := v.([]interface{}); ok {
|
||||
for _, s := range vals {
|
||||
if data, ok := s.(map[string]interface{}); ok {
|
||||
var pkg *CustomConfiguration
|
||||
modelBuff, _ := json.Marshal(data)
|
||||
err := json.Unmarshal(modelBuff, &pkg)
|
||||
if err == nil {
|
||||
strs = append(strs, pkg)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -100,6 +137,18 @@ func (this *CustomConfiguration) GetInts(key string) (strs []int) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
if v, exist := (*this)[strings.ToLower(key)]; exist {
|
||||
if vals, ok := v.([]interface{}); ok {
|
||||
for _, s := range vals {
|
||||
if str, ok := s.(float64); ok {
|
||||
strs = append(strs, int(str))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
func (this *CustomConfiguration) GetInt(key string) int {
|
||||
|
@ -108,6 +157,12 @@ func (this *CustomConfiguration) GetInt(key string) int {
|
|||
return int(val)
|
||||
}
|
||||
}
|
||||
|
||||
if v, exist := (*this)[strings.ToLower(key)]; exist {
|
||||
if val, ok := v.(float64); ok {
|
||||
return int(val)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -117,5 +172,10 @@ func (this *CustomConfiguration) GetBool(key string) bool {
|
|||
return val
|
||||
}
|
||||
}
|
||||
if v, exist := (*this)[strings.ToLower(key)]; exist {
|
||||
if val, ok := v.(bool); ok {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue