go-patterns_skill

This skill provides production-ready Go patterns for concurrency, error handling, HTTP servers, and testing to boost reliability and performance.
  • Python

2.5k

GitHub Stars

2

Bundled Files

2 months ago

Catalog Refreshed

3 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill openclaw/skills --skill go-patterns

  • _meta.json278 B
  • SKILL.md7.2 KB

Overview

This skill collects production-ready Go language patterns and best practices for Go 1.24+ focused on reliable services, concurrency, error handling, and tooling. It bundles idiomatic approaches for context propagation, errgroup concurrency, error wrapping, HTTP and gRPC servers, PostgreSQL access with pgx, testing, and building CLIs with Cobra. The guidance targets practical, maintainable code and real-world deployment considerations.

How this skill works

The skill inspects and documents common coding patterns, providing concrete examples and recipes you can paste into projects. It emphasizes mandatory context propagation for I/O, safe concurrent patterns using errgroup and cancellation, error wrapping with %w, and structured project layouts. It also covers database access choices, HTTP server setup with graceful shutdown, gRPC interceptors, testing strategies, and performance profiling.

When to use it

  • Starting a new Go service or refactoring an existing one to follow idiomatic patterns
  • Implementing concurrent processing that must respect cancellation and resource limits
  • Designing HTTP or gRPC servers with graceful shutdown and observability
  • Choosing a database strategy (pgx, GORM, sqlc) for performance or developer ergonomics
  • Building command-line tools with consistent UX using Cobra

Best practices

  • Always accept context.Context as the first parameter for I/O and long-running operations
  • Use errgroup.WithContext and SetLimit to manage goroutine lifecycles and cap concurrency
  • Wrap errors with fmt.Errorf(...%w...) and use errors.Is / errors.As for checks
  • Follow the standard project layout (cmd/, internal/, pkg/) and keep internal packages unexported
  • Profile before optimizing (pprof) and prefer pre-allocating slices and strings.Builder for hot paths

Example use cases

  • Concurrent batch processing where items are processed with a maximum worker count and shared cancellation
  • An HTTP API using chi with middleware, request IDs, and a graceful shutdown sequence
  • A PostgreSQL-backed service using pgx connection pooling and explicit sql queries for performance
  • A testable service design using interfaces for repositories and table-driven unit tests with mocks
  • A multi-command CLI built with Cobra, including flags, subcommands, and validation

FAQ

Use pgx for high-performance raw SQL and fine control; choose GORM when ORM features and relationship handling speed development; pick sqlc for type-safe generated queries when you want SQL-first development.

How do I prevent goroutine leaks?

Ensure goroutines respect ctx.Done(), use errgroup.WithContext to tie lifecycles to the caller, and always close channels or provide cancellation paths for long-running loops.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational