|
@@ -355,36 +355,22 @@ func ToFloat64(data any) (float64, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func Zero[T any]() T {
|
|
func Zero[T any]() T {
|
|
- var zeroAny T
|
|
|
|
|
|
+ var zeroT T
|
|
|
|
|
|
- zeroValue := reflect.New(reflect.TypeOf(zeroAny)).Elem()
|
|
|
|
- if zeroValue.Kind() != reflect.Pointer {
|
|
|
|
- zero(&zeroValue)
|
|
|
|
- return zeroValue.Interface().(T)
|
|
|
|
|
|
+ zeroAnyValue := reflect.ValueOf(zeroT)
|
|
|
|
+ zeroAny := ZeroValueToAny(zeroAnyValue)
|
|
|
|
+ if zeroAny == nil {
|
|
|
|
+ return zeroT
|
|
}
|
|
}
|
|
|
|
|
|
- zeroValue.Set(reflect.New(zeroValue.Type().Elem()))
|
|
|
|
- elemValue := PointerValueElem(zeroValue)
|
|
|
|
- zero(&elemValue)
|
|
|
|
-
|
|
|
|
- return zeroValue.Interface().(T)
|
|
|
|
|
|
+ return zeroAny.(T)
|
|
}
|
|
}
|
|
|
|
|
|
-func ZeroValue(v reflect.Value) reflect.Value {
|
|
|
|
- zeroValue := reflect.New(v.Type()).Elem()
|
|
|
|
- if zeroValue.Kind() != reflect.Pointer {
|
|
|
|
- zero(&zeroValue)
|
|
|
|
- return zeroValue
|
|
|
|
|
|
+func ZeroValueToAny(v reflect.Value) any {
|
|
|
|
+ if v.Kind() == reflect.Invalid {
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
- zeroValue.Set(reflect.New(zeroValue.Type().Elem()))
|
|
|
|
- elemValue := PointerValueElem(zeroValue)
|
|
|
|
- zero(&elemValue)
|
|
|
|
-
|
|
|
|
- return zeroValue
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func ZeroValueToAny(v reflect.Value) any {
|
|
|
|
zeroValue := reflect.New(v.Type()).Elem()
|
|
zeroValue := reflect.New(v.Type()).Elem()
|
|
if zeroValue.Kind() != reflect.Pointer {
|
|
if zeroValue.Kind() != reflect.Pointer {
|
|
zero(&zeroValue)
|
|
zero(&zeroValue)
|