Linux command
vet 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Vet the current package
go vet
Vet all packages recursively
go vet ./...
Vet a specific package
go vet [package/path]
Output diagnostics as JSON
go vet -json ./...
Print commands without executing them
go vet -n ./...
Use a custom analysis tool
go vet -vettool=[path/to/analyzer] ./...
说明
go vet examines Go source code and reports suspicious constructs that the compiler does not catch, using heuristics that do not guarantee all reports are genuine problems. It checks for issues such as incorrect printf format strings, unreachable code, suspicious function calls, misuse of sync primitives, and incorrect struct tags. The tool is part of the standard Go toolchain and runs without executing the code. It is typically used alongside tests and linters as part of a continuous integration workflow. Individual analyzers can be enabled or disabled (e.g., `-printf=false`). Run `go tool vet help` to see available analyzers and their flags.
参数
- -n
- Print commands that would be executed, but do not run them.
- -x
- Print commands as they are executed.
- -json
- Output diagnostics in JSON format.
- -vettool _prog_
- Select a different analysis tool with alternative or additional checks.
- -c _int_
- Display offending line with this many lines of context.
- ./...
- Wildcard that matches all packages in the current module recursively.
FAQ
What is the vet command used for?
go vet examines Go source code and reports suspicious constructs that the compiler does not catch, using heuristics that do not guarantee all reports are genuine problems. It checks for issues such as incorrect printf format strings, unreachable code, suspicious function calls, misuse of sync primitives, and incorrect struct tags. The tool is part of the standard Go toolchain and runs without executing the code. It is typically used alongside tests and linters as part of a continuous integration workflow. Individual analyzers can be enabled or disabled (e.g., `-printf=false`). Run `go tool vet help` to see available analyzers and their flags.
How do I run a basic vet example?
Run `go vet` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n do in vet?
Print commands that would be executed, but do not run them.