From 22dc0a767af4dd24bdb1d0402457cfab5359337c Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Wed, 4 Dec 2024 16:35:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=B8=8D=E5=8C=BA=E5=88=86=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/config.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/common/config.go b/common/config.go index 3347b65..a15c366 100644 --- a/common/config.go +++ b/common/config.go @@ -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 }