40 lines
675 B
Go
40 lines
675 B
Go
package utilities
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
func GetSettingString(m map[string]any, name string, fallback string) string {
|
|
|
|
v, ok := m[name]
|
|
|
|
if !ok {
|
|
return fallback
|
|
}
|
|
|
|
switch val := v.(type) {
|
|
case string:
|
|
return val
|
|
case bool:
|
|
if val {
|
|
return "1"
|
|
} else {
|
|
return "0"
|
|
}
|
|
case int:
|
|
return strconv.FormatInt(int64(val), 10)
|
|
case int64:
|
|
return strconv.FormatInt(val, 10)
|
|
case uint:
|
|
return strconv.FormatUint(uint64(val), 10)
|
|
case uint64:
|
|
return strconv.FormatUint(val, 10)
|
|
case float32:
|
|
return strconv.FormatFloat(float64(val), 'f', -1, 64)
|
|
case float64:
|
|
return strconv.FormatFloat(val, 'f', -1, 64)
|
|
default:
|
|
panic("unknown type")
|
|
}
|
|
}
|