mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
24 lines
388 B
Go
24 lines
388 B
Go
|
|
package utils
|
||
|
|
|
||
|
|
import (
|
||
|
|
"reflect"
|
||
|
|
"strconv"
|
||
|
|
)
|
||
|
|
|
||
|
|
func GetString4Map(m map[string]interface{}, key string) string {
|
||
|
|
return m[key].(string)
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetInt4Map(m map[string]interface{}, key string) int {
|
||
|
|
i := m[key]
|
||
|
|
iKind := reflect.TypeOf(i).Kind()
|
||
|
|
if iKind == reflect.Int {
|
||
|
|
return i.(int)
|
||
|
|
}
|
||
|
|
if iKind == reflect.String {
|
||
|
|
i, _ := strconv.Atoi(i.(string))
|
||
|
|
return i
|
||
|
|
}
|
||
|
|
return 0
|
||
|
|
}
|