Sets up Go development environment with proper tooling, linting, testing, and dependencies. Runs go mod tidy, configures golangci-lint, sets up testing framework, and verifies build. Use when starting work on Go projects, after cloning Go repositories, setting up CI/CD for Go, or troubleshooting Go environment issues.
Install
npx skillscat add meriley/claude-code-skills/setup-go Install via the SkillsCat registry.
Go Development Setup Skill
Purpose
Quickly set up and verify a Go development environment with all necessary tooling.
Workflow
Step 1: Verify Go Installation
go versionExpected: Go 1.20 or higher
If not installed:
❌ Go not found
Install Go:
- macOS: brew install go
- Linux: https://golang.org/doc/install
- Windows: https://golang.org/doc/install
After installing, verify: go versionStep 2: Check Project Structure
Verify go.mod exists:
ls go.modIf doesn't exist:
No go.mod found. Initialize Go module:
go mod init <module-name>
Example:
go mod init github.com/username/projectStep 3: Install Dependencies
go mod download
go mod tidyExplanation:
go mod download: Downloads all dependenciesgo mod tidy: Removes unused dependencies, adds missing ones
Report:
✅ Dependencies installed
Direct dependencies: X
Indirect dependencies: Y
Go version: 1.21Step 4: Setup golangci-lint
Check if installed:
golangci-lint versionIf not installed:
# macOS/Linux
brew install golangci-lint
# Or using go install
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latestCreate or verify .golangci.yml configuration:
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gofmt
- goimports
- revive
- misspell
- gocritic
- unparam
linters-settings:
errcheck:
check-blank: true
govet:
check-shadowing: true
revive:
severity: warning
issues:
exclude-use-default: false
max-same-issues: 0
run:
timeout: 5m
tests: trueRun linter to verify:
golangci-lint runStep 5: Setup Testing
Run existing tests:
go test ./... -vSetup test coverage:
go test ./... -cover -coverprofile=coverage.outView coverage:
go tool cover -func=coverage.outGenerate HTML coverage report:
go tool cover -html=coverage.out -o coverage.htmlReport:
✅ Tests completed
Tests run: X
Tests passed: X
Tests failed: Y
Coverage: Z%Step 6: Verify Build
go build ./...Report:
✅ Build successful
All packages compile without errors.If build fails:
❌ Build failed
[Show error output]
Common issues:
1. Missing dependencies: run 'go mod tidy'
2. Syntax errors: check the reported files
3. Import cycle: review package dependenciesStep 7: Setup Code Generation (if needed)
Check for generate directives:
grep -r "//go:generate" . --include="*.go"If found, run:
go generate ./...Step 8: Setup Makefile (Optional but Recommended)
Check if Makefile exists:
ls MakefileIf doesn't exist, create one:
.PHONY: build test lint fmt clean coverage
build:
go build -v ./...
test:
go test -v ./...
coverage:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
lint:
golangci-lint run
fmt:
gofmt -s -w .
goimports -w .
vet:
go vet ./...
clean:
go clean
rm -f coverage.out coverage.html
all: fmt lint test buildVerify Makefile:
make allStep 9: Setup Git Hooks (Optional)
Create pre-commit hook:
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
set -e
echo "Running pre-commit checks..."
# Format code
echo "Formatting code..."
gofmt -s -w .
# Run linter
echo "Running linter..."
golangci-lint run
# Run tests
echo "Running tests..."
go test ./...
echo "✅ Pre-commit checks passed"
EOF
chmod +x .git/hooks/pre-commitStep 10: Summary Report
✅ Go Development Environment Setup Complete
Go version: 1.21.5
Module: github.com/user/project
Tooling:
✅ go mod tidy - Dependencies up to date
✅ golangci-lint - Configured and passing
✅ Tests - X tests passing (Y% coverage)
✅ Build - Successful
✅ Makefile - Created with common targets
✅ Git hooks - Pre-commit hook installed
Quick Commands:
- Build: make build OR go build ./...
- Test: make test OR go test ./...
- Lint: make lint OR golangci-lint run
- Format: make fmt OR gofmt -s -w .
- Coverage: make coverage
Ready to start development!Common Go Commands Reference
Dependency Management
go mod init <module> # Initialize new module
go mod download # Download dependencies
go mod tidy # Clean up dependencies
go mod verify # Verify dependencies
go mod vendor # Vendor dependencies
go get <package> # Add new dependency
go get -u <package> # Update dependencyBuilding
go build # Build current package
go build ./... # Build all packages
go build -o binary # Build with custom name
go install # Build and install binaryTesting
go test ./... # Run all tests
go test -v ./... # Verbose output
go test -cover ./... # With coverage
go test -race ./... # Race condition detection
go test -bench=. # Run benchmarks
go test -run TestName # Run specific testCode Quality
go fmt ./... # Format code
goimports -w . # Fix imports
go vet ./... # Static analysis
golangci-lint run # Comprehensive linting
go mod tidy # Clean dependenciesDebugging
go build -gcflags="-m" # Escape analysis
go build -race # Race detector
go test -cpuprofile cpu.prof # CPU profiling
go test -memprofile mem.prof # Memory profiling
go tool pprof cpu.prof # Analyze profileTroubleshooting
Issue: "go: command not found"
Solution: Go not installed or not in PATH
# macOS
brew install go
# Verify PATH includes Go
echo $PATH | grep goIssue: "cannot find package"
Solution: Missing dependency
go mod download
go mod tidyIssue: "import cycle not allowed"
Solution: Circular dependency between packages
- Review package dependencies
- Refactor to break the cycle
- Consider extracting shared code to new package
Issue: "golangci-lint: command not found"
Solution: Linter not installed
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Ensure $GOPATH/bin is in PATH
export PATH=$PATH:$(go env GOPATH)/binIssue: Tests failing with "race condition detected"
Solution: Concurrent access to shared data
# Run with race detector to identify issue
go test -race ./...
# Fix by using proper synchronization (mutex, channels, etc.)Best Practices
- Always run
go mod tidybefore committing - Use
golangci-lintfor comprehensive linting - Enable race detector in CI/CD:
go test -race ./... - Target 90%+ test coverage
- Use
goimportsinstead ofgofmt(handles imports too) - Run
go vetto catch common mistakes - Use Makefiles for consistent commands across team
- Vendor dependencies for reproducible builds (optional)
Integration with Other Skills
This skill may be invoked by:
quality-check- When checking Go code qualityrun-tests- When running Go tests