init
This commit is contained in:
35
utils/ext.go
Normal file
35
utils/ext.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user