2025-03-14 21:59:59 -06:00
|
|
|
# go
|
|
|
|
|
|
|
|
|
|
> Manage Go source code.
|
|
|
|
|
> Some subcommands such as `build` have their own usage documentation.
|
2025-12-16 10:20:31 -07:00
|
|
|
> More information: <https://pkg.go.dev/cmd/go>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Download and install a package, specified by its import path:
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`go get {{path/to/package}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Compile and run a source file (it has to contain a `main` package):
|
|
|
|
|
|
|
|
|
|
`go run {{file}}.go`
|
|
|
|
|
|
|
|
|
|
- Compile a source file into a named executable:
|
|
|
|
|
|
|
|
|
|
`go build -o {{executable}} {{file}}.go`
|
|
|
|
|
|
|
|
|
|
- Compile the package present in the current directory:
|
|
|
|
|
|
|
|
|
|
`go build`
|
|
|
|
|
|
|
|
|
|
- Execute all test cases of the current package (files have to end with `_test.go`):
|
|
|
|
|
|
|
|
|
|
`go test`
|
|
|
|
|
|
|
|
|
|
- Compile and install the current package:
|
|
|
|
|
|
|
|
|
|
`go install`
|
|
|
|
|
|
|
|
|
|
- Initialize a new module in the current directory:
|
|
|
|
|
|
|
|
|
|
`go mod init {{module_name}}`
|