|
@@ -721,6 +721,32 @@ func MathFloor(x float64) int {
|
|
|
return int(math.Floor(x + 0/5))
|
|
|
}
|
|
|
|
|
|
+// data 转换成ret
|
|
|
+func Bind(data interface{}, ret interface{}) error {
|
|
|
+ v := reflect.ValueOf(ret)
|
|
|
+ if v.Kind() != reflect.Ptr {
|
|
|
+ return fmt.Errorf("ptr input ret needed as type as input type %s", v.Kind())
|
|
|
+ }
|
|
|
+ havdata := false
|
|
|
+ var bk interface{}
|
|
|
+ if v.Elem().Kind() == reflect.Slice {
|
|
|
+ t := reflect.Zero(reflect.TypeOf(v.Elem().Interface()))
|
|
|
+ bk = v.Elem().Interface()
|
|
|
+ v.Elem().Set(t)
|
|
|
+ havdata = true
|
|
|
+ }
|
|
|
+ _data, _ := json.MarshalIndent(data, "", " ")
|
|
|
+ err := json.Unmarshal(_data, ret)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ if havdata {
|
|
|
+ v.Elem().Set(reflect.ValueOf(bk))
|
|
|
+ }
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
//string
|
|
|
func InterfaceToStr(x interface{}) string {
|
|
|
switch st := reflect.ValueOf(x); st.Kind() {
|