Go Idioms Guide
Paste the following prompt into your AI chat to install this skill:
Please follow https://skillhub.cn/install/skillhub.md to install @user_3c6cb52e/golang-idioms-lr-ao90.
About this skill
Problem
Go code often diverges less on syntax and more on conventions: how errors are wrapped, where logging happens, whether interfaces are defined near consumers or implementations, and whether goroutines and channels form cancellable, closeable, awaitable structures. In medium-sized modules, these details can make error semantics hard to reason about and raise testing and refactoring costs.
How it works
The skill provides Go idioms rules that can be used as review guidance, generation constraints, or engineering standards:
- Error handling: use
fmt.Errorf("context: %w", err)to add context, and use%wto preserveerrors.Is/errors.As; use sentinel errors for expected conditions; avoid both logging and returning the same error. - Interface design: prefer defining interfaces where they are used; favor small, composable interfaces; reuse
io.Reader,io.Writer, andfmt.Stringer; name single-method interfaces by method plusersuffix. - Concurrency patterns: constrain
goroutineandchannelusage around patterns such as worker pools and channel direction semantics, e.g.jobs <-chan Jobas an input channel.
Boundaries
It fits Go services, CLIs, and internal frameworks where review or code generation needs a consistent style. It does not replace architecture decisions; for legacy error codes, business interfaces, or existing concurrency models, combine it with team standards and avoid applying generic idioms blindly to performance-sensitive paths.
Use Cases
- During Go service review, check whether errors use `fmt.Errorf` context and `%w` wrapping.
- When designing module interfaces, ensure they are consumer-defined, small, and composable.
- While implementing a worker pool, verify goroutine and channel directions express input, output, and cancellation.
- When generating CLI code, constrain error returns and logging to avoid duplicate handling of one error.
Best For
- Backend engineers reviewing Go services who want consistent error wrapping, interface placement, and concurrency boundaries.
- Engineers generating Go modules with LLMs who need prompt constraints that reduce low-quality boilerplate.
- Architects maintaining internal SDKs who want `errors.Is`, interface slicing, and channel semantics in team standards.
- Tech leads mentoring juniors who need quick PR checks for error handling and goroutine usage issues.
Related Skills
Creates themed learning sites by generating flashcards, lessons, quizzes, index, and progress pages into a deployable website.
End-to-end mathematical optimization modeling with Gurobi and Python, covering data validation, code generation, solving, result analysis, and iterative revision.
Executes an Eversheet Web CDP login using externally supplied baseUrl, username, and password, then verifies the page reaches a logged-in home state.
Clarify product goals, user flows, pages, data, and permissions, then output an implementation-ready development prompt and lightweight spec.