|
| 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 |
0 commit comments