Linux command
go 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run a program
go run [main.go]
Build an executable
go build
Run tests
go test
Download dependencies
go mod download
Format code
go fmt ./...
说明
go is the tool for managing Go source code. It provides commands for building, testing, running, and managing Go programs and modules. The tool handles compilation, dependency management, testing, and code quality. Go modules provide versioned dependency management. The toolchain is self-contained and produces statically linked binaries by default.
参数
- build
- Compile packages and dependencies.
- run
- Compile and run program.
- test
- Run tests.
- mod
- Module maintenance.
- get
- Download and install packages.
- fmt
- Format source code.
- vet
- Report likely mistakes.
- doc
- Show documentation.
- install
- Compile and install packages.
- generate
- Run code generators.
- clean
- Remove build cache and binaries.
- env
- Print Go environment variables.
- --help
- Display help information.
FAQ
What is the go command used for?
go is the tool for managing Go source code. It provides commands for building, testing, running, and managing Go programs and modules. The tool handles compilation, dependency management, testing, and code quality. Go modules provide versioned dependency management. The toolchain is self-contained and produces statically linked binaries by default.
How do I run a basic go example?
Run `go run [main.go]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does build do in go?
Compile packages and dependencies.