一、Go的相关插件工具简介
- golint 代码的风格检测
- go fmt 重新格式化Go源代码
- goimports 引用包的优化
- gometalinter 同时运行Go lint工具并规范化其输出
- go vet 代码的语法检查
二、插件工具使用
1、golint
- 安装golint
#下载源码
> go get github.com/golang/lint/
#编译包并生产可执行文件到bin目录下($GOPATH/bin)
> go install github.com/golang/lint/golint
- 打开goland进行设置,点击
Settings
打开设置 - 选择
External Tools
并新建+
选择External Tools并新建+ - 参数说明:
Name : golint #Tool名称
Description: golint #Tool描述
Program : $GOPATH\bin\golint.exe #选择golint可执行文件的位置
Atguments: $FilePath$ #魔法变量(执行当前go文件的路径)
Working directory: $ProjectFileDir$ #魔法变量(当前项目的路径)
-
设置快捷键Keymap -> External Tools -> External Tools -> golint -> Add Keyboard Shortcut(右键)
新增快捷键 -
连续按着键盘进行设置
设置快捷键 -
选择项目中的一个go文件进行【快捷键测试】
测试结果 -
git commit 提交代码测试
提交代码测试
注意:这是commit
提交之后才进行代码检测
2、gofmt+goimports+gometalinter
- 打开goland进行设置,点击
Settings
打开设置 - goland 设置插件,
File Watchers
->+
-> 分别点击安装go fmt
、goimports
、gometalinter
image.png - 修改代码后按住
Ctrl+S
就可以看到效果了
gofmt 、 goimports直接就可以看见代码修改的效果
gometalinter的效果
gometalinter
3、go tool vet
- 使用go tool vet针对单个文件进行代码检查
> go tool vet global/init.go
测试结果
go vet
- 使用go tool vet针对整个项目进行代码检查
> go tool vet ../zlsc_image
测试结果
>go tool vet ../zlsc_image
..\zlsc_image\global\init.go:144: struct field c_ip has json tag but is not exported
..\zlsc_image\global\init.go:145: struct field college_id has json tag but is not exported
..\zlsc_image\global\init.go:146: struct field status has json tag but is not exported
..\zlsc_image\global\init.go:147: struct field camera_status has json tag but is not exported
..\zlsc_image\global\init.go:148: struct field sign_status has json tag but is not exported
..\zlsc_image\utils\file.go:160: Println call has possible formatting directive %s
..\zlsc_image\utils\file.go:172: Println call has possible formatting directive %s
..\zlsc_image\utils\file.go:184: Println call has possible formatting directive %s
..\zlsc_image\utils\image.go:89: unreachable code
..\zlsc_image\utils\image.go:79: image/jpeg.Options composite literal uses unkeyed fields
..\zlsc_image\utils\pic.go:388: unreachable code
..\zlsc_image\utils\uid.go:57: result of fmt.Sprintf call not used
..\zlsc_image\utils\uid.go:61: result of fmt.Sprintf call not used
..\zlsc_image\utils\uid.go:70: result of fmt.Sprintf call not used
..\zlsc_image\utils\uid.go:98: result of fmt.Sprintf call not used
..\zlsc_image\utils\convert\map.go:182: unreachable code
..\zlsc_image\utils\convert\map.go:196: unreachable code
..\zlsc_image\utils\convert\map.go:210: unreachable code
..\zlsc_image\utils\convert\map.go:224: unreachable code
网友评论