Go 安装配置golint
原文链接:http://zhoubotong.site/post/3.html
一. Golint介绍
Golint 是一个源码检测工具用于检测代码规范
Golint 不同于gofmt, Gofmt用于代码格式化
Golint会对代码做以下几个方面检查
package注释 必须按照 “Package xxx 开头”
package命名 不能有大写字母、下划线等特殊字符
struct、interface等注释 必须按照指定格式开头
struct、interface等命名
变量注释、命名
函数注释、命名
各种语法规范校验等
二. Golint安装
首先在我们下载的位置,通过右键git bash here 打开git控制台
下载golang 的 lint,下载地址:https://github.com/golang/lint
mkdir -p $GOPATH/src/golang.org/x/
cd $GOPATH/src/golang.org/x/
git clone https://github.com/golang/lint.git
git clone https://github.com/golang/tools.git
到目录$GOPATH/src/golang.org/x/lint/golint中运行
go install
安装成功后我们会在C:\用户\77293\go\bin 目录下面看到我们的golint.exe执行程序,这个目录是我们安装go包的目录路径。
三、配置golint
1、打开goland Idea
2、选择项目栏File 下拉选中 Setting,打开设置控制面板
设置参数说明:
Program $GOPATH\src\bin\golint.exe (直接填写glint.exe所在路径即可)
Arguments $FilePath$
Working directory $ProjectFileDir$
3、选中keymap > External Tools > External Tools > golint进行快捷键配置
四、golint使用
选择我们需要检测的go文件
按住我们之前设置的快捷键,就可以进行检测了,比如说结果如下:
五. Golint检验规则
golint检测代码有2种方式
1: golint file2: golint directory
golint校验常见的问题如下所示
don't use ALL_CAPS in Go names; use CamelCase
不能使用下划线命名法,使用驼峰命名法exported function Xxx should have comment or be unexported
外部可见程序结构体、变量、函数都需要注释var statJsonByte should be statJSONByte
var taskId should be taskID
通用名词要求大写
iD/Id -> ID
Http -> HTTP
Json -> JSON
Url -> URL
Ip -> IP
Sql -> SQLdon't use an underscore in package name
don't use MixedCaps in package name; xxXxx should be xxxxx
包命名统一小写不使用驼峰和下划线comment on exported type Repo should be of the form "Repo ..." (with optional leading article)
注释第一个单词要求是注释程序主体的名称,注释可选不是必须的type name will be used as user.UserModel by other packages, and that stutters; consider calling this Model
外部可见程序实体不建议再加包名前缀if block ends with a return statement, so drop this else and outdent its block
if语句包含return时,后续代码不能包含在else里面should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
errors.New(fmt.Sprintf(…)) 建议写成 fmt.Errorf(…)receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"
receiver名称不能为this或selferror var SampleError should have name of the form ErrSample
错误变量命名需以 Err/err 开头should replace num += 1 with num++
should replace num -= 1 with num--
a+=1应该改成a++,a-=1应该改成a–
最新文章
- android onNewIntent调用时机
- Oracle解锁,解决“ora00054:资源正忙”错误
- 基于Java Mina 通信框架的JT/T809转发服务器设计
- XPath的使用
- Durandal介绍
- oracle DBA学习方法交流
- Qt和KDevelop在Linux下安装(qt-x11-commercial-src-4.3.1和kdevelop-3.5.0)
- Using Feedback as a Tool
- GDI+ 学习记录(26): 显示图像 - Image
- Android之 Fragment
- Android中ListView嵌套GridView的简单消息流UI(解决宽高问题)
- python2.7_2.2_在套接字服务器上使用ForkingMixIn
- Google调试技巧总结
- smoke.js是一款基于HTML5 Canvas的逼真烟雾特效js插件。通过该js插件,可以非常轻松的在页面中制作出各种烟雾效果。
- 《C++ Primer》之面向对象编程(四)
- java 类与类之间的关系 及uml图
- 4.1、Libgdx的生命周期
- [HEOI2018] 秘密袭击coat
- golang使用 gzip压缩
- 火热的线上APP的源码分享,开箱即用