golint的简易使用方法
Go  /  管理员 发布于 4年前   910
根据作者的说法:
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/lintgo install github.com/golang/lint
二、执行方式:
golint 文件名或者目录
检查结果如下:
import-dot.go:6:8: should not use dot importselse.go:11:9: if block ends with a return statement, so drop this else and outdent its blocksort.go:11:1: exported method T.Len should have comment or be unexportedsort.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++
更多golang开发知识请关注golang教程栏目。
以上就是golint的简易使用方法的详细内容,更多请关注其它相关文章!
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号