Go - go vet的用法
go vet介绍
Vet examines Go source code and reports suspicious constructs, such as
Printf calls whose arguments do not align with the format string. Vet uses
heuristics that do not guarantee all reports are genuine problems, but it
can find errors not caught by the compilers.
Vet is normally invoked through the go command. This command vets the
package in the current directory:
go vet
whereas this one vets the packages whose path is provided:
go vet my/project/...
文档中可以了解到,go vet
命令可以用来检测错误。
╭─ben at MacBook Pro in ~/go/src/github.com/goinaction/code/chapter3/tmp on master✘✘✘ 2021/08/29 - 15:28:58
╰─⠠⠵ cat go_vet.go
package main
import "fmt"
func main() {
fmt.Printf("The quick brown fox jumped over lazy dogs", 3.14)
}
╭─ben at MacBook Pro in ~/go/src/github.com/goinaction/code/chapter3/tmp on master✘✘✘ 2021/08/29 - 15:29:05
╰─⠠⠵ go vet go_vet.go
# command-line-arguments
./go_vet.go:7:19: Printf call has arguments but no formatting directives
后记
保持一个良好的习惯:在提交到仓库之前,最好要运行对你的code base执行go vet扫错。