Skip to content

Commit 26cf7ec

Browse files
authored
Update go-tips.cn.md
1 parent 43cd20e commit 26cf7ec

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

go-tips.cn.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ title: Go JSON 使用小技巧
1212
参考文章:http://attilaolah.eu/2014/09/10/json-and-struct-composition-in-go/
1313

1414
# 临时忽略struct字段
15+
16+
```golang
17+
type User struct {
18+
Email string `json:"email"`
19+
Password string `json:"password"`
20+
// many more fields…
21+
}
22+
```
23+
24+
临时忽略掉Password字段
25+
26+
```golang
27+
json.Marshal(struct {
28+
*User
29+
Password bool `json:"password,omitempty"`
30+
}{
31+
User: user,
32+
})
33+
```
34+
1535
# 临时粘合两个struct
1636
# 一个json切分成两个struct
1737
# 临时改名struct的字段

0 commit comments

Comments
 (0)