qbtrade/pkg/dynamic/typevalue.go
2024-06-27 22:42:38 +08:00

25 lines
584 B
Go

package dynamic
import "reflect"
// https://github.com/xiaojun207/go-base-utils/blob/master/utils/Clone.go
func NewTypeValueInterface(typ reflect.Type) interface{} {
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
dst := reflect.New(typ).Elem()
return dst.Addr().Interface()
}
dst := reflect.New(typ)
return dst.Interface()
}
// ToReflectValues convert the go objects into reflect.Value slice
func ToReflectValues(args ...interface{}) (values []reflect.Value) {
for i := range args {
arg := args[i]
values = append(values, reflect.ValueOf(arg))
}
return values
}