golang-patterns

Applies idiomatic Go patterns for error handling, concurrency, interfaces, and package design.

37|4|Updated Apr 11, 2026
One-click install
npx skills add https://github.com/jmrplens/gitlab-mcp-server --skill golang-patterns-jmrplens
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-patterns
Source: https://github.com/jmrplens/gitlab-mcp-server/tree/main/.github/skills/golang-patterns
Command: npx skills add https://github.com/jmrplens/gitlab-mcp-server --skill golang-patterns-jmrplens

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Go developers often write code that compiles but violates community idioms, leading to unmaintainable error handling, goroutine leaks, and poorly designed interfaces. This Skill provides a reference of idiomatic Go patterns so code reviews, refactors, and new implementations follow established conventions. ## Core Features & Use Cases - Error Handling Patterns: Error wrapping with context, custom error types, sentinel errors, and errors.Is/errors.As checking. - Concurrency Patterns: Worker pools, context-based cancellation and timeouts, graceful shutdown, errgroup coordination, and goroutine leak prevention. - Design Patterns: Interface design, functional options, struct embedding, package organization, and memory optimization with sync.Pool and preallocation. - Modern Go Features: Coverage of Go 1.23-1.27 features including range-over-func iterators, slog, errors.Join, omitzero JSON tags, and http.CrossOriginProtection. - Use Case: When reviewing a pull request that spawns goroutines without cancellation handling, use this Skill to rewrite the code with proper context propagation and buffered channels to prevent leaks. ## Quick Start Review my Go HTTP server code and refactor it to follow idiomatic Go patterns for error handling and graceful shutdown.

Frequently Asked Questions about golang-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors idiomatically in Go?

Wrap errors with context using fmt.Errorf and the %w verb, define sentinel errors with errors.New for common cases, and check them with errors.Is and errors.As. Never ignore errors with the blank identifier unless explicitly documented.

How do I prevent goroutine leaks in Go?

Use buffered channels or select statements with context cancellation so goroutines never block forever on sends. Coordinate multiple goroutines with errgroup and always propagate context for cancellation and timeouts.

What is the functional options pattern in Go?

The functional options pattern configures structs by passing variadic Option functions to a constructor, each setting one field. It provides clean defaults and extensible APIs without large config structs or many constructor variants.

Should Go interfaces be defined by the provider or consumer?

Interfaces should be defined in the consumer package where they are used, not by the provider. Keep interfaces small and focused, ideally single-method, and accept interfaces as parameters while returning concrete struct types.

What modern Go features should I use in Go 1.24 and later?

Use the omitzero JSON tag to omit zero-value fields, errors.Join for combining multiple errors, sync.OnceValue for lazy initialization, and log/slog for structured logging. Go 1.27 also allows assigning promoted embedded fields directly in composite literals.