This commit is contained in:
Yun
2024-10-28 20:33:26 +08:00
4 changed files with 122 additions and 116 deletions
+4 -2
View File
@@ -7,6 +7,9 @@ import (
// interface 转 int64
func ToInt64(val interface{}) (i int64, err error) {
if val == nil {
return 0, errors.New("value is nil")
}
switch v := val.(type) {
case int:
@@ -33,8 +36,6 @@ func ToInt64(val interface{}) (i int64, err error) {
return int64(v), nil
case float64:
return int64(v), nil
case nil:
return 0, nil
case string:
return strconv.ParseInt(v, 10, 64)
case bool:
@@ -46,3 +47,4 @@ func ToInt64(val interface{}) (i int64, err error) {
}
return 0, errors.New("convx.ToInt64: unknown type")
}