Note: Full agent documentation and language-specific best practices are maintained at: https://github.com/lox/agent-docs
- Format Go:
go fmt ./... - Test Go:
go test ./... - Test with coverage:
go test -cover ./... - Build:
go build ./... - Mod tidy:
go mod tidy - Vet code:
go vet ./... - Install dependencies:
go mod download
- Package structure: Use clear, descriptive package names (avoid generic names like
util) - Naming: Use camelCase for private, PascalCase for public exports
- Error handling: Always handle errors explicitly, use
fmt.Errorffor wrapping - Context: Pass
context.Contextas first parameter for cancellation/timeouts - Interfaces: Keep interfaces small and focused (prefer composition)
- Testing: Use table-driven tests, test files end with
_test.go - Documentation: Comment all public functions/types with proper godoc format
- Formatting: Always run
go fmtbefore committing - Imports: Group standard library, third-party, and local imports separately
- Variables: Use short variable names in small scopes, descriptive names in larger scopes
- Constants: Use
constblocks for related constants - Struct tags: Use consistent tag formatting (json, yaml, etc.)
- Error types: Create custom error types for domain-specific errors
- Branch naming: Use simple descriptive names without prefixes
- Commits: Commit signing enabled, write clear commit messages
- Dependencies: Keep
go.modclean, usego mod tidyregularly - Security: Never commit secrets, use environment variables or secure vaults
- CI/CD: Ensure tests pass before merging, use automated linting
- Benchmarking: Use
go test -bench=.for performance testing - Profiling: Use
go tool pproffor CPU/memory profiling - Race detection: Run tests with
-raceflag - Static analysis: Use
golangci-lintfor comprehensive code analysis - Dependency management: Regular security updates with
go list -m -u all