Skip to content

Commit 5f256bb

Browse files
committed
new article: [go tools](/2022/08/vscode_go_tools.md)
1 parent cb8729f commit 5f256bb

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

2022/08/go_post_json.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type Resp struct {
1818

1919
> struct field code has json tag but is not exported
2020
21+
可以用 vscode 的 gomodifytags 一键给结构体的所有字段加上 json tag
22+
2123
## json post 请求
2224

2325
我试着写了个 json POST 请求的例子,请求用 map 序列化 body 响应用结构体反序列化

2022/08/vscode_go_tools.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [go tools](/2022/08/vscode_go_tools.md)
2+
3+
今天写 go 代码时 vscode go 插件警告我有两个核心的工具 dlv(用于 debug/test) 和 staticcheck (用于 lint) 我没装
4+
5+
<https://github.com/golang/vscode-go/wiki/tools#goplay>
6+
7+
```
8+
go: /usr/bin/go: go version go1.19 linux/amd64
9+
10+
gotests: not installed
11+
gomodifytags: not installed
12+
impl: not installed
13+
goplay: not installed
14+
dlv: /home/w/go/bin/dlv (version: v1.9.0 built with go: go1.19)
15+
staticcheck: /home/w/go/bin/staticcheck (version: v0.3.3 built with go: go1.19)
16+
gopls: /home/w/go/bin/gopls (version: v0.9.4 built with go: go1.19)
17+
```
18+
19+
然后我点通过 vscode 安装,结果 vscode 不知为何 GOPROXY 没有设置上导致被墙装不上,还是我手动装
20+
21+
```
22+
go install golang.org/x/tools/gopls@latest
23+
24+
#go install pkg.go.dev/honnef.co/go/tools/staticcheck@latest
25+
go install honnef.co/go/tools/cmd/staticcheck@latest
26+
go install github.com/go-delve/delve/cmd/dlv@latest
27+
28+
go install github.com/haya14busa/goplay/cmd/goplay@latest
29+
go install github.com/josharian/impl@latest
30+
go install github.com/fatih/gomodifytags@latest
31+
go install github.com/cweill/gotests/gotests@latest
32+
```
33+
34+
上述几个常用工具我点评下:
35+
36+
- staticcheck: 检查比 go vet 细致,go vet 发现不了的 unused var 它能发现
37+
- gomodifytags: 一键给结构体的每个字段添加 json tag
38+
39+
还有就是开源社区常用的源码 license header 检查工具
40+
41+
> go install github.com/apache/skywalking-eyes/cmd/license-eye@latest
42+
43+
---
44+
45+
```
46+
学习了 gomodifytags 可以给结构体自动加上 json tag
47+
这就是我想要的 serde(rename_all="camelCase") 效果
48+
之前我懒得一个个字段加 json tag
49+
golang 反序列我习惯 map/interface 乱糊(interface 嵌套多了真的巨慢)例如
50+
51+
json["data"].(map[string]interface{})["records"].([]interface{})[0].(map[str
52+
```
53+
54+
> https://twitter.com/ospopen/status/1561973110844592128

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- [文章列表 - 吴翱翔的博客](/)
22
- **2022-08**
3+
- [go tools](/2022/08/vscode_go_tools.md)
34
- [Stream::try_clone](/2022/08/stream_try_clone.md)
45
- [牙髓血运重建术](/2022/08/revascularization_procedure.md)
56
- [go post json 初体验](/2022/08/go_http_client.md)

0 commit comments

Comments
 (0)