Browse Source

add more tool

Paul 6 years ago
parent
commit
eeffb0155c
1 changed files with 19 additions and 0 deletions
  1. 19
    0
      utils/unit.go

+ 19
- 0
utils/unit.go View File

@@ -1 +1,20 @@
1 1
 package utils
2
+
3
+import (
4
+	"encoding/json"
5
+)
6
+
7
+// 去掉struct的空字段
8
+func Struct2Slimming(input interface{}) (interface{}, error) {
9
+	bs, err := json.Marshal(input)
10
+	if err != nil {
11
+		return nil, err
12
+	}
13
+
14
+	var output interface{}
15
+	if err = json.Unmarshal(bs, &output); err != nil {
16
+		return nil, err
17
+	}
18
+
19
+	return output, nil
20
+}