Go: Running Code & Tools
Running Go
go run main.go # compile and run (no binary left behind)
go build # compile to binary named after the directory
go build -o myapp . # specify output name
go install # compile + move to $GOPATH/bin
Editors
- VS Code — install the Go extension by the Go team (gopls language server built-in)
- GoLand — JetBrains IDE for Go (paid, but excellent)
- Vim/Neovim with
goplsLSP server for completion and diagnostics
Module system (Go modules)
Go 1.11+ uses modules instead of GOPATH. Every project starts with:
go mod init github.com/yourname/myapp # creates go.mod
go get github.com/gorilla/mux # add a dependency
go mod tidy # clean up deps
go mod vendor # copy deps to vendor/
Testing
go test ./... # run all tests
go test -v # verbose output
go test -bench . # benchmarks
// math_test.go — test files end with _test.go
func TestAdd(t *testing.T) {
result := Add(2, 3)
expected := 5
if result != expected {
t.Errorf("Add(2,3) = %d; want %d", result, expected)
}
}
Quick check below!