with one click
go-best-practices
// Go development best practices. Idiomatic Go, error handling, concurrency patterns, testing. Use when writing Go code.
// Go development best practices. Idiomatic Go, error handling, concurrency patterns, testing. Use when writing Go code.
C++ development best practices. Modern C++20/23, RAII, zero-overhead abstractions, safety. Use when writing C++ code.
Docker and container best practices. Multi-stage builds, security, optimization. Use when creating Dockerfiles.
Observability best practices. Logging, metrics, tracing, alerting. Essential for production services. Use for any backend service.
React Native development. Cross-platform code, native modules, performance. Use when building mobile apps.
Test-Driven Development workflow. Write failing test first, implement code to pass, then refactor. Essential for all languages: Go, TypeScript, C++, Python. Use before any implementation task.
Use when the user wants to commit, push, and open a pull request for the current changes. Stages relevant files, writes a descriptive commit message, pushes the branch, opens a PR against main, and posts an /oc review comment so opencode automatically reviews and approves if ready.
| name | go-best-practices |
| description | Go development best practices. Idiomatic Go, error handling, concurrency patterns, testing. Use when writing Go code. |
| compatibility | opencode |
Follow Go proverbs and community standards for all Go code.
// Always wrap errors with context
if err != nil {
return fmt.Errorf("failed to do operation: %w", err)
}
// Custom error types for known conditions
var NotFoundError struct{ Name string }
func (e NotFoundError) Error() string {
return fmt.Sprintf("not found: %s", e.Name)
}
// Use channels for coordination, mutexes for state
// Worker pool pattern
jobs := make(chan Job, workerCount)
results := make(chan Result, workerCount)
// Start workers
for i := 0; i < workerCount; i++ {
go worker(jobs, results)
}
// All API calls must accept context
func DoSomething(ctx context.Context, arg Arg) (Result, error) {
req, err := http.NewRequestWithContext(ctx, ...)
// ...
}
// Table-driven tests
tests := []struct {
name string
input Arg
expected Result
}{
{"case 1", Arg{...}, Expected{...}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := DoSomething(tt.input)
assert.Equal(t, tt.expected, result)
})
}
go fmt ./...
go vet ./...
golangci-lint run
go test -race -coverprofile=coverage.out ./...
go build -o binary ./cmd/...