Easy to use golint

Release: 2020-04-15 17:56:25
forward
4304 people have browsed it

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
Copy after login

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
Copy after login

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!

Related labels:
go
source:oschina.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!