package sysconfmod import ( "91porn-server/common/log" "encoding/json" "strconv" ) type ConfMap map[string]string func (c ConfMap) getValue(code VCode) string { obj, ok := c[string(code)] if !ok { log.Error("配置项 " + string(code) + " 未找到配置值!") return "" } return obj } // GetStrSlice 获取字符串数组 func (c ConfMap) GetStrSlice(code VCode) []string { var res []string v := c.getValue(code) err := json.Unmarshal([]byte(v), &res) if err != nil { log.Error("配置项 " + string(code) + " 不是有效的数组值!") } return res } // GetObject 对象类型配置 func (c ConfMap) GetObject(code VCode) map[string]string { res := make(map[string]string) v := c.getValue(code) err := json.Unmarshal([]byte(v), &res) if err != nil { log.Error("配置项 " + string(code) + " 不是有效的对象值!") } return res } // GetString 字符串配置项 func (c ConfMap) GetString(code VCode) string { return c.getValue(code) } // GetBool 布尔配置项 func (c ConfMap) GetBool(code VCode) bool { v := c.getValue(code) res, err := strconv.ParseBool(v) if err != nil { res = false } return res } // GetInt 数字型配置项 func (c ConfMap) GetInt(code VCode) int64 { v := c.getValue(code) res, err := strconv.ParseInt(v, 10, 64) if err != nil { res = 0 } return res } // GetFloat 浮点型配置项 func (c ConfMap) GetFloat(code VCode) float64 { v := c.getValue(code) res, err := strconv.ParseFloat(v, 64) if err != nil { res = 0.00 } return res }