Skip to content

Commit bc0e724

Browse files
committed
增加数据深拷贝
1 parent 451f11b commit bc0e724

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

utils/xcopy/copy.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package xcopy
22

3+
import "encoding/json"
4+
35
func DeepCopy(value interface{}) interface{} {
46
if valueMap, ok := value.(map[string]interface{}); ok {
57
newMap := make(map[string]interface{})
@@ -25,3 +27,17 @@ func AppendStrings(a, b []string) []string {
2527
}
2628
return a
2729
}
30+
31+
func Convert(data interface{}, target interface{}) error {
32+
bytes, err := json.Marshal(data)
33+
if err != nil {
34+
return err
35+
}
36+
37+
err = json.Unmarshal(bytes, &target)
38+
if err != nil {
39+
return err
40+
}
41+
42+
return err
43+
}

0 commit comments

Comments
 (0)