Comprehensive Go language support for opencode with Go-specific improvements and modern development workflows.
The Go integration provides a complete development environment for Go projects with intelligent tooling, cross-compilation support, security auditing, and performance optimization features.
- Smart Project Setup - Automatic detection and configuration
- Cross-Compilation - Build for multiple platforms simultaneously
- Comprehensive Testing - Unit tests, benchmarks, and coverage
- Code Quality - Multiple linters and formatters
- Security - Vulnerability scanning and dependency auditing
- Performance - Benchmarking and profiling support
- Modern Go Tooling - Support for Go 1.16+ features
- Go Modules Integration - Full module support with vendor option
- Workspace Support - Go 1.18+ workspace configuration
- Race Detector - Built-in race condition detection
- Coverage Reporting - Multiple format support (HTML, text, XML)
Configure Go project with intelligent defaults and Go-specific improvements.
/go-setup [options] [project-path]Options:
--quick,-q- Quick setup with defaults--project-type TYPE-module,cli,web,library,workspace--module-name NAME- Go module name--linter TOOL-golangci-lint,staticcheck,revive--formatter TOOL-gofmt,goimports--reconfigure,-r- Reconfigure existing project
Examples:
/go-setup --project-type cli
/go-setup --module-name github.com/myorg/myapp
/go-setup --linter golangci-lint --formatter goimportsBuild Go projects with cross-compilation and optimization features.
/go-build [options] [package]Options:
--output,-o FILE- Output binary name--target OS/ARCH- Cross-compilation target--race- Enable race detector--cross-compile- Build for all platforms--clean- Clean before building--ldflags FLAGS- Linker flags for version embedding
Examples:
/go-build --race
/go-build --target linux/amd64
/go-build --cross-compile
/go-build --ldflags "-X main.version=1.0.0"Run comprehensive tests with coverage and benchmarking.
/go-test [options] [test-pattern]Options:
--coverage,-c- Enable coverage--race- Enable race detector--bench,-b- Run benchmarks--timeout DURATION- Test timeout--count N- Run tests N times--parallel N- Parallel execution
Examples:
/go-test --coverage --race
/go-test --bench --benchmem
/go-test --timeout 30s --count=3Lint code with multiple linter support and auto-fix capabilities.
/go-lint [options] [paths...]Options:
--fix- Auto-fix issues--linter TOOL- Choose linter--timeout DURATION- Linter timeout--fast- Run only fast linters--config FILE- Configuration file
Examples:
/go-lint --fix
/go-lint --linter staticcheck
/go-lint --timeout 10mFormat code with import organization and simplification.
/go-format [options] [paths...]Options:
--write,-w- Write changes--diff,-d- Show differences--check- Check without modifying--formatter TOOL-gofmtorgoimports--simplify,-s- Apply simplifications
Examples:
/go-format --write
/go-format --check
/go-format --formatter goimports --writeManage Go modules with security auditing and update management.
/go-mod [action] [options]Actions:
tidy- Add missing, remove unused modulesvendor- Create vendor directoryverify- Verify dependency integritygraph- Print dependency graphwhy- Explain why package is neededsecurity,audit- Security auditupdate- Update specific packageupdate-all- Update all dependencies
Examples:
/go-mod tidy
/go-mod security
/go-mod update-all
/go-mod why github.com/pkg/errorsCommand-line interface applications with cmd/ structure.
/go-setup --project-type cli --module-name github.com/user/myappStructure:
project/
├── cmd/
│ └── myapp/
│ └── main.go
├── internal/
│ └── ...
├── go.mod
└── .opencode/
└── go-config.json
HTTP API services with common web dependencies.
/go-setup --project-type web --module-name github.com/user/apiFeatures:
- Gorilla mux integration
- CORS middleware support
- Structured logging
- Health check endpoints
Reusable Go packages for distribution.
/go-setup --project-type library --module-name github.com/user/mylibStructure:
project/
├── pkg/
│ └── mylib/
│ └── mylib.go
├── go.mod
└── .opencode/
└── go-config.json
Multi-module projects (Go 1.18+).
/go-setup --project-type workspaceStructure:
project/
├── api/
│ └── go.mod
├── cli/
│ └── go.mod
├── shared/
│ └── go.mod
├── go.work
└── .opencode/
└── go-config.json
{
"go": {
"version": "1.21.0",
"module": "github.com/user/project",
"projectType": "cli",
"usingModules": true,
"usingWorkspace": false,
"tools": {
"linter": "golangci-lint",
"formatter": "goimports",
"testRunner": "gotestsum"
},
"linting": {
"enabled": true,
"tool": "golangci-lint",
"configFile": ".golangci.yml"
},
"testing": {
"enabled": true,
"tool": "go test",
"flags": ["-v", "-race"],
"coverage": {
"enabled": true,
"threshold": 80
}
},
"build": {
"flags": [],
"ldflags": [],
"targets": ["linux/amd64", "darwin/amd64", "darwin/arm64", "windows/amd64"]
}
}
}run:
timeout: 5m
modules-download-mode: vendor
linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
issues:
exclude-rules:
- path: _test\.go
linters:
- gosec
output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true| Tool | Purpose | Priority |
|---|---|---|
golangci-lint |
Comprehensive linting | Recommended |
staticcheck |
Static analysis | High |
goimports |
Import organization | High |
gotestsum |
Test runner | Recommended |
delve |
Debugging | Optional |
gosec |
Security scanning | Recommended |
pprof |
Profiling | Optional |
The system provides platform-specific installation guides:
# macOS
brew install go golangci-lint
# Linux
sudo apt-get install golang-go
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh
# Windows
# Download from https://golang.org/dl/
scoop install golangci-lint- Linux:
amd64,arm64,arm - macOS:
amd64,arm64 - Windows:
amd64,386
/go-build --cross-compileOutputs:
myapp-linux-amd64myapp-linux-arm64myapp-darwin-amd64myapp-darwin-arm64myapp-windows-amd64.exe
# Manual cross-compilation
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /go-build- Unit Tests - Function and method testing
- Benchmarks - Performance measurement
- Examples - Documentation examples
- Integration Tests - Component integration
/go-test --coverage --coverage-format html --coverage-output coverage.htmlFormats:
html- Interactive HTML reporttext- Text summaryxml- CI integration format
/go-test --bench --benchmem --benchtime 5sMetrics:
- Time per operation
- Memory allocations
- Bytes per operation
- Allocations per operation
/go-mod securityChecks:
- Known vulnerabilities
- Outdated dependencies
- License compliance
- Checksum verification
/go-lint --linter gosecScans:
- Hardcoded credentials
- SQL injection risks
- File inclusion vulnerabilities
- Command injection
# CPU profiling
go test -cpuprofile cpu.prof -bench .
# Memory profiling
go test -memprofile mem.prof -bench .# Run benchmarks
/go-test --bench --benchtime 10s > current.txt
# Compare with previous run
benchcmp previous.txt current.txtname: Go CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- run: /go-test --coverage --race
- run: /go-lint
- run: /go-format --check
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- run: /go-build --cross-compile
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- run: /go-mod securitystages:
- test
- build
- security
go-test:
stage: test
image: golang:1.21
script:
- /go-test --coverage
- /go-lint
- /go-format --check
go-build:
stage: build
image: golang:1.21
script:
- /go-build --cross-compile
artifacts:
paths:
- bin/
go-security:
stage: security
image: golang:1.21
script:
- /go-mod securityError: cannot find module providing package github.com/example/pkg
Solution:
/go-deps tidy
# or
go get github.com/example/pkgError: build constraints exclude all Go files
Solution:
# Check build tags
/go-build --tags "integration,debug"
# Review .go files for build constraintsWARNING: DATA RACE
Solution:
- Run with
--raceflag to detect - Use mutexes or channels for synchronization
- Review concurrent access patterns
- Use
cmd/for executables - Use
internal/for private code - Use
pkg/for public libraries - Keep
go.modat root
- Write table-driven tests
- Use subtests for organization
- Include benchmarks for performance-critical code
- Maintain high test coverage
- Run
/go-lint --fixregularly - Use
/go-format --checkin CI - Enable race detector in tests
- Audit dependencies monthly
- Run
/go-mod securityin CI - Use
gosecfor code scanning - Keep dependencies updated
- Review vulnerability reports
- Profile before optimizing
- Use benchmarks for comparison
- Monitor memory allocations
- Consider cross-compilation targets
# Initialize module
go mod init github.com/user/project
# Migrate dependencies
go mod tidy
# Verify migration
/go-mod verify# Remove dep files
rm Gopkg.toml Gopkg.lock
# Initialize module
go mod init
# Convert dependencies
go mod tidy# Remove vendor directory
rm -rf vendor/
# Initialize module
go mod init
# Let Go manage dependencies
/go-mod tidySee the example Go projects for complete working examples:
- Hello World - Basic CLI application
- Web Service - HTTP API example
- Library Package - Reusable package example
- Workspace - Multi-module workspace example
Error: golangci-lint not found
Solution:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latestError: permission denied
Solution:
# Check file permissions
ls -la
# Fix permissions
chmod +x /path/to/toolError: out of memory
Solution:
- Increase system memory
- Use
--fastflag with linters - Limit parallel execution
# Verbose output
/go-build --verbose
# Dry run
/go-deps --dry-run tidy
# Debug environment
go env- Add tool detection to
languages/golang/tool-detector.js - Update installation guides
- Add configuration options
- Update documentation
- Add new command to
scripts/commands/ - Update command runner
- Add documentation
- Create examples
# Run Go tests
/go-test
# Test cross-compilation
/go-build --cross-compile
# Verify linting
/go-lint
# Check formatting
/go-format --checkGo integration is part of the opencode project. See the main LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review examples
- Open an issue on GitHub
- Consult the Go community resources