mirror of
https://github.com/taigrr/jety.git
synced 2026-04-02 03:19:03 -07:00
fix slice returners
This commit is contained in:
38
getters.go
38
getters.go
@@ -143,8 +143,17 @@ func (c *ConfigManager) GetStringSlice(key string) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch val := v.Value.(type) {
|
switch val := v.Value.(type) {
|
||||||
case []string:
|
case []any:
|
||||||
return val
|
var ret []string
|
||||||
|
for _, v := range val {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case string:
|
||||||
|
ret = append(ret, v)
|
||||||
|
default:
|
||||||
|
ret = append(ret, fmt.Sprintf("%v", v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -191,8 +200,29 @@ func (c *ConfigManager) GetIntSlice(key string) []int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch val := v.Value.(type) {
|
switch val := v.Value.(type) {
|
||||||
case []int:
|
case []any:
|
||||||
return val
|
var ret []int
|
||||||
|
for _, v := range val {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case int:
|
||||||
|
ret = append(ret, v)
|
||||||
|
case string:
|
||||||
|
i, err := strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ret = append(ret, i)
|
||||||
|
case float32:
|
||||||
|
ret = append(ret, int(v))
|
||||||
|
case float64:
|
||||||
|
ret = append(ret, int(v))
|
||||||
|
case nil:
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user