The primary functionality of the Golang Build package is the Go build system. It includes a number of what Sublime Text refers to as "variants." It also includes a couple of regular Sublime Text commands for common, related tasks.
To use the Go build system, open the Tools > Build System menu and select Go.
The variants included with the build system include:
- Build, which executes
go build - Run, which executes
go runwith the current filepath - Test, which executes
go test - Benchmark, which executes
go test -bench=. - Install, which executes
go install - Cross-Compile (Interactive), which executes
go buildwithGOOSandGOARCHset - Clean, which executes
go clean
Once the Go build system is selected, the command palette can be used to run any of the variants.
On Sublime Text 3, the command palette entries will be:
Build with: GoBuild with: Go - Run(see Cancelling a Build below)Build with: Go - TestBuild with: Go - BenchmarkBuild with: Go - InstallBuild with: Go - Cross-Compile (Interactive)Build with: Go - Clean
On Sublime Text 2, the command palette entries will be:
Build: BuildBuild: Run(see Cancelling a Build below)Build: TestBuild: BenchmarkBuild: InstallBuild: Cross-Compile (Interactive)Build: Clean
If a build is running and needs to be stopped, the command palette will contain
an extra entry Go: Cancel Build. When using the Go - Run command with a
long-running program, you'll need to use this cancel command palette entry to
stop the running process.
For convenience, you can bind this command to a shortcut by inserting the
following into your Preferences -> Keybindings - Default file:
{ "keys": ["command+shift+c"], "command": "golang_build_cancel" }If the output panel for a build is closed, it can be re-opened by using the
command palette to run Go: Reopen Build Output. Once a new build is
started, the old build output is erased.
In addition to the build system variants, two other command palette commands are available:
Go: Get, which executesgo getafter prompting for a URLGo: Open Terminal, which opens a terminal and sets relevant Go environment variables
To control the environment variables used with the build system, please read the configuration documentation.
For information on the available commands, their arguments, example key bindings and command palette entries, please read the commands documentation.