Golang lint easy to use method

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

According to the author's statement:

Golint is a linter for Go source code. Golint differs from GOFMT. GOFMT reformats Go Source code, Whereasgolint prints out style mistakes. Golint differs from Govet. Govet is concerned with correctness, whereasgolint are concerned with coding style. Golint is on use with Google, and itseeks to match the accepted style of the open source Go project.

The bottom line is that golint is used to check for inadequate specifications in the go code.

First, compile and generate executable program

1, download Golang lint, download address: Https://github.com/golang/lint

2. Extract files to $gopath/src/github.com/golang/lint

3. Run go build in directory $gopath/src/github.com/golang/lint/golint.

4, in the current directory has golint executable program

The simplest way, of course, is to:

Go get github.com/golang/lintgo Install Github.com/golang/lint

Second, the way of implementation:

Golint file name or directory

The results of the inspection are as follows:

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 OU Tdent its blocksort.go:11:1: Exported method T.len should has comment or be unexportedsort.go:20:1: Exported method U.oth Er should has comment or be unexported

As you can see from the above output, Golint's recommendations for go code.

What the golint will check:

Variable name specification variable declaration, like var str string = "Test", there will be a warning, should be var str = "Test" case problem, uppercase export package to have comments X + = 1 should be + + and so on ...







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.