经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Go语言 » 查看文章
Golint的简易使用方法
来源:cnblogs  作者:回首笑人间  时间:2019/1/28 9:42:50  对本文有异议

根据作者的说法:

  1. Golint is a linter for Go source code.
  2. Golint differs from gofmt. Gofmt reformats Go source code, whereas
  3. golint prints out style mistakes.
  4. Golint differs from govet. Govet is concerned with correctness, whereas
  5. golint is concerned with coding style. Golint is in use at Google, and it
  6. 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的可执行程序

当然,最简单的方式是:

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

二、执行方式:

  1. golint 文件名或者目录

检查结果如下:

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

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

golint 会检查的内容:

  1. 变量名规范
  2. 变量的声明,像var str string = "test",会有警告,应该var str = "test"
  3. 大小写问题,大写导出包的要有注释
  4. x += 1 应该 x++
  5. 等等……

使用注意事项

如果使用命令下载安装不通的情况下,建议使用第一种方法

在使用golint命令检查时,需要把golint.exe文件放在你要检查的名录下,这样在使用命令时才能找到该执行程序。

原文链接:http://www.cnblogs.com/Survivalist/p/10260107.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号