fix: failed to assert when int is compared with int64 #1232

This commit is contained in:
xucong053
2022-04-11 18:19:18 +08:00
parent 318e1173a2
commit 1aafdd8401
4 changed files with 40 additions and 2 deletions
+34
View File
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"reflect"
"strconv"
"strings"
@@ -198,6 +199,39 @@ func Interface2Float64(i interface{}) (float64, error) {
return 0, errors.New("failed to convert interface to float64")
}
func TypeNormalization(raw interface{}) interface{} {
rawValue := reflect.ValueOf(raw)
switch rawValue.Kind() {
case reflect.Int:
return rawValue.Int()
case reflect.Int8:
return rawValue.Int()
case reflect.Int16:
return rawValue.Int()
case reflect.Int32:
return rawValue.Int()
case reflect.Float32:
return rawValue.Float()
case reflect.Uint:
return rawValue.Uint()
case reflect.Uint8:
return rawValue.Uint()
case reflect.Uint16:
return rawValue.Uint()
case reflect.Uint32:
return rawValue.Uint()
default:
return raw
}
}
func InterfaceType(raw interface{}) string {
if raw == nil {
return ""
}
return reflect.TypeOf(raw).String()
}
var ErrUnsupportedFileExt = fmt.Errorf("unsupported file extension")
// LoadFile loads file content with file extension and assigns to structObj