Home >Backend Development >Golang >Easy to use golint

Easy to use golint

尚
forward
2020-04-15 17:56:254365browse

Easy to use golint

According to the author:

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.

In a word, Golint is used to check for insufficient standards in go code.

1. Compile and generate executable programs

1. Download golang’s lint, download address: https://github.com/golang/lint

2. Unzip the file to $GOPATH/src/github.com/golang/lint

3. Go to the directory $GOPATH/src/github.com/golang/lint/golint and run go build ./

4. There is an executable program of golint in the current directory

Of course, the simplest way is:

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

2. Execution method:

golint File name or directory

The check results are as follows:

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

As you can see from the above output, golint gives suggestions for go code.

What golint will check:

Variable name specification

Variable declaration, like var str string = "test", there will be a warning, it should be var str = "test "

There is a case problem. The capitalized export package must have comments

x = 1 should be x

For more golang development knowledge, please pay attention to PHP Chinese Golang tutorial column.

The above is the detailed content of Easy to use golint. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:oschina.net. If there is any infringement, please contact admin@php.cn delete