engine/utils/ext.go

36 lines
618 B
Go
Raw Permalink Normal View History

2024-02-11 01:31:01 +08:00
package utils
import (
"strconv"
"strings"
)
func If(condition bool, trueValue, falseValue interface{}) interface{} {
if condition {
return trueValue
}
return falseValue
}
//如果首字母是小写字母, 则变换为大写字母
func FirstToUpper(str string) string {
if str == "" {
return ""
}
return strings.ToUpper(str[:1]) + strings.ToLower(str[1:])
}
func ParseParams(in map[string]string) map[string]interface{} {
out := make(map[string]interface{})
for k, v := range in {
fv, err := strconv.ParseFloat(v, 64)
if err != nil {
out[k] = fv
} else {
out[k] = v
}
}
return out
}