This is a created article in which the information may have evolved or changed.
We all know that Golang offers a lot of rich and powerful command-line tools. But so many tools, what exactly does each one do? This article is a rough chat about the role and usage of several commonly used tools.
gofmt
GOFMT is a code formatting tool that only organizes code formatting to ensure that everyone's code is formatted uniformly.
Attach the effect before and after GOFMT:
golint
The Golint tool is a code quality check that gives some best practice guidelines. Look at the following code:
After the Golint.
main.go:8:5: error var SomeError should have name of the form ErrFoo main.go:8:5: exported var SomeError should have comment or be unexported main.go:16:9: if block ends with a return statement, so drop this else and outdent its block
First line: SomeError
the format of the variable should be the beginning of err.
The second line: SomeError
the uppercase start can be referenced outside the package, so you need to write a comment at the declaration. or change to lowercase, not to be quoted outside the package.
The third line: the IF condition has a return statement, so the else block is not required.
After the modification, the golint is executed again, and the error disappears.