根据作者的说法:

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开发知识请关注PHP中文网golang教程栏目。

更多相关文章

  1. 代码详解使用Go基于WebSocket构建视频直播弹幕系统
  2. Golang中Bit数组如何实现(代码示例)
  3. 在java中使用dom4j解析xml(示例代码)
  4. Java生成和解析XML格式文件和字符串的实例代码
  5. php 修改、增加xml结点属性的实现代码
  6. php操作XML、读取数据和写入数据的实现代码
  7. 解析php DOMElement 操作xml 文档的实现代码
  8. XML解析之SAX解析过程代码详解
  9. 使用正则表达式进行xml数据验证的代码实例详解

随机推荐

  1. if语句的用法是什么
  2. c语言源程序结构是怎样的?
  3. c语言编译后生成什么文件
  4. c语言如何实现玫瑰花
  5. 用c语言编写的代码程序是什么?
  6. c语言用什么软件编写?
  7. C语言如何编程生日快乐代码
  8. char数组如何转string
  9. C程序的完整开发过程包括哪几步
  10. c++ vector用法是什么