File tree 3 files changed +5
-28
lines changed
3 files changed +5
-28
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ require (
6
6
github.com/LyricTian/captcha v1.1.0
7
7
github.com/LyricTian/gzip v0.1.1
8
8
github.com/LyricTian/queue v1.2.0
9
- github.com/LyricTian/structs v1.1.1
10
9
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
11
10
github.com/bwmarrin/snowflake v0.3.0
12
11
github.com/casbin/casbin/v2 v2.4.1
@@ -27,6 +26,7 @@ require (
27
26
github.com/google/gops v0.3.8
28
27
github.com/google/uuid v1.1.1
29
28
github.com/google/wire v0.4.0
29
+ github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
30
30
github.com/jinzhu/gorm v1.9.12
31
31
github.com/jinzhu/now v1.1.1 // indirect
32
32
github.com/json-iterator/go v1.1.9
Original file line number Diff line number Diff line change @@ -10,8 +10,6 @@ github.com/LyricTian/gzip v0.1.1 h1:R8lzUek+tFN4frAXNWOhIKoJaLyFLVOnogBJMBMj9xY=
10
10
github.com/LyricTian/gzip v0.1.1 /go.mod h1:JT7ISZwfIQvoUG2Z/RFjTQA7vBObrGAi9OLXTA+Vycs =
11
11
github.com/LyricTian/queue v1.2.0 h1:OaEiS5D5dQOMFyvvrq11o0uJdAMXDf5nRJggVDFEonY =
12
12
github.com/LyricTian/queue v1.2.0 /go.mod h1:CMJcrjcVYLOqN2FnVpXqYJzITcDJNdlq7VLkPXyhduw =
13
- github.com/LyricTian/structs v1.1.1 h1:Bn+/o3WgFavzNxXAb+V2xrPsAghda/xXZ6epPkt9a/0 =
14
- github.com/LyricTian/structs v1.1.1 /go.mod h1:/flA4L8Ltg7IrugE2yV9F9umQrDe9aPBItaO95HNyP4 =
15
13
github.com/PuerkitoBio/purell v1.1.0 /go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0 =
16
14
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI =
17
15
github.com/PuerkitoBio/purell v1.1.1 /go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0 =
@@ -165,6 +163,8 @@ github.com/google/wire v0.4.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1
165
163
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI =
166
164
github.com/hpcloud/tail v1.0.0 /go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU =
167
165
github.com/inconshreveable/mousetrap v1.0.0 /go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8 =
166
+ github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o =
167
+ github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a /go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s =
168
168
github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q =
169
169
github.com/jinzhu/gorm v1.9.12 /go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs =
170
170
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E =
Original file line number Diff line number Diff line change 1
1
package util
2
2
3
3
import (
4
- "reflect"
5
-
6
- "github.com/LyricTian/structs"
4
+ "github.com/jinzhu/copier"
7
5
)
8
6
9
7
// StructMapToStruct 结构体映射
10
8
func StructMapToStruct (s , ts interface {}) error {
11
- if ! structs .IsStruct (s ) || ! structs .IsStruct (ts ) {
12
- return nil
13
- }
14
-
15
- ss , tss := structs .New (s ), structs .New (ts )
16
- for _ , tfield := range tss .Fields () {
17
- if ! tfield .IsExported () {
18
- continue
19
- }
20
-
21
- if tfield .IsEmbedded () && tfield .Kind () == reflect .Struct {
22
- for _ , tefield := range tfield .Fields () {
23
- if f , ok := ss .FieldOk (tefield .Name ()); ok {
24
- tefield .Set2 (f .Value ())
25
- }
26
- }
27
- } else if f , ok := ss .FieldOk (tfield .Name ()); ok {
28
- tfield .Set2 (f .Value ())
29
- }
30
- }
31
-
32
- return nil
9
+ return copier .Copy (ts , s )
33
10
}
You can’t perform that action at this time.
0 commit comments