golint的使用方法介绍

发布时间:2020-04-17 10:42:52 作者:小新
来源:亿速云 阅读:1302

今天小编给大家分享的是golint的使用方法介绍,很多人都不太了解,今天小编为了让大家更加了解golint的使用方法,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。

golint的使用方法介绍

根据作者的说法:

Golint is a linter for Go source code.

Golint differs from gofmt. Gofmt reformats Go source code, whereas

golint prints out style mistakes.

Golint differs from govet. Govet is concerned with correctness, whereas

golint is concerned with coding style. Golint is in use at Google, and it

seeks to match the accepted style of the open source Go project.

一句话就是Golint用于检查go代码中不够规范的地方。

一、编译及生成可执行程序

1、下载golang 的 lint,下载地址:https://github.com/golang/lint

2、解压文件到$GOPATH/src/github.com/golang/lint

3、到目录$GOPATH/src/github.com/golang/lint/golint中运行go build ./

4、在当前目录有golint的可执行程序

当然,最简单的方式是:

go get github.com/golang/lint
go install github.com/golang/lint

二、执行方式:

golint 文件名或者目录

检查结果如下:

import-dot.go:6:8: should not use dot imports
else.go:11:9: if block ends with a return statement, so drop this else and outdent its block
sort.go:11:1: exported method T.Len should have comment or be unexported
sort.go:20:1: exported method U.Other should have comment or be unexported

从上面输出可以看到,golint对go代码给出的建议。

golint 会检查的内容:

变量名规范

变量的声明,像var str string = "test",会有警告,应该var str = "test"

大小写问题,大写导出包的要有注释

x += 1 应该 x++

以上就是golint的使用方法的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注亿速云行业资讯频道哦!

推荐阅读:
  1. Dockerfile的介绍和使用方法
  2. vscode golint安装失败的解决方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

golint go

上一篇:购买传统服务器还是云主机?有什么区别

下一篇:Nginx + Tomcat 负载均衡集群详细介绍

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》