golang-patterns_skill

This skill helps you apply idiomatic Go patterns to write simpler, safer, and more maintainable code.
  • JavaScript

46.5k

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 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 affaan-m/everything-claude-code --skill golang-patterns

  • SKILL.md13.7 KB

Overview

This skill codifies idiomatic Go patterns, best practices, and conventions to help you build robust, efficient, and maintainable Go applications. It focuses on readability, safe concurrency, error handling, package and API design, and performance optimizations. Use it as a practical checklist during development, reviews, and refactors.

How this skill works

The skill inspects common Go design areas and recommends concrete patterns: making zero values useful, accepting interfaces and returning concrete types, clear error wrapping, and safe concurrency constructs. It highlights anti-patterns, suggests tooling and linter settings, and provides concise code idioms and examples you can apply directly to functions, packages, and system-level design. Outputs are actionable guidelines aimed at reducing bugs and improving long-term maintainability.

When to use it

  • When writing new Go modules, libraries, or services.
  • During code reviews to flag non-idiomatic constructs and bugs.
  • While refactoring to simplify interfaces, reduce global state, and improve testability.
  • When designing concurrent systems, worker pools, or graceful shutdown flows.
  • Before committing linter and CI changes to enforce consistent style.

Best practices

  • Prefer simplicity and clear control flow; return early and keep the happy path unindented.
  • Design types whose zero value is usable without explicit initialization.
  • Accept interfaces in function parameters and return concrete struct types.
  • Wrap errors with context using fmt.Errorf(...%w...) and use errors.Is / errors.As for checks.
  • Use context for cancellation/timeouts and errgroup to coordinate goroutines.
  • Avoid package-level mutable state; inject dependencies via constructors.

Example use cases

  • Implementing an HTTP service with dependency-injected database and graceful shutdown.
  • Refactoring a leaking goroutine into a context-aware worker pool or errgroup-based routine.
  • Designing a small, focused interface in the consumer package instead of exposing it globally.
  • Improving performance by preallocating slices, using strings.Builder, or sync.Pool for buffers.
  • Adding linters and go tooling (gofmt, goimports, staticcheck, golangci-lint) to CI.

FAQ

Prefer returning concrete types to keep callers simple; accept interfaces for inputs so callers can pass flexible implementations.

When is it acceptable to ignore an error?

Only ignore errors when it genuinely has no observable effect (rare). Otherwise handle or explicitly document why it is safe to ignore.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
golang-patterns skill by affaan-m/everything-claude-code | VeilStrat