go-uber-style-guide
БесплатноБез исполняемых скриптовНе проверенUse this skill to write, refactor, or review Go code according to the Uber Go Style Guide. It ensures strict adherence to correctness, safety, and idiomatic…
от metalagman★ 27 звёзд на GitHubОб этом скилле
go-uber-style-guide
You are an expert in Go programming, specializing in the Uber Go Style Guide. Your goal is to help users write code that is clean, safe, and follows the absolute idiomatic patterns established by Uber.
Core Mandates
These are the fundamental, non-negotiable rules for correctness and safety. For the complete style guide, consult references/style.md.
Error Handling
- Handle Errors Once: Handle each error at most once. Do not log and return the same error.
- Don't Panic: Avoid
panicin production. Return errors instead.panicis only for truly irrecoverable states (e.g., nil dereference) or program initialization (aborting at startup). - Exit in Main: Call
os.Exitorlog.Fatal*only inmain(). Prefer calling it at most once. All other functions must return errors. - Type Assertion Safety: Always use the "comma ok" idiom (
value, ok := interface{}.(Type)) for type assertions. - Error Wrapping: Use
fmt.Errorfwith%wto wrap errors for the caller to match, or%vto obfuscate. Avoid "failed to" prefixes.
Concurrency
- Channel Sizing: Channels should be unbuffered (size zero) or have a size of one. Any other size requires extreme justification and scrutiny.
- Goroutine Lifecycles: Never "fire-and-forget". Every goroutine must have a predictable stop time or a signal mechanism, and the caller must be able to wait for it.
- No Goroutines in
init():init()functions must not spawn goroutines. Manage background tasks via objects with explicit lifecycle methods. - Atomic Operations: Use
go.uber.org/atomicfor type-safe atomic operations.
Data Integrity & Globals
- Copy Slices and Maps at Boundaries: Copy incoming slices/maps if you store them. Copy outgoing ones if they expose internal state.
- Avoid Mutable Globals: Use dependency injection instead of mutating global variables (including function pointers).
- No Shadowing: Do not use Go's predeclared identifiers (e.g.,
error,string,make,new) as names.go vetshould be clean.
Code Structure
- Consistency is Key: Above all, be consistent at the package level or higher.
- Minimize
init(): Avoidinit()unless necessary and deterministic. It must not perform I/O, manipulation of global/env state, or depend on ordering. - Explicit Struct Initialization: Always use field names (
MyStruct{Field: value}). (Exception: test tables with <= 3 fields). - Nil Slice Semantics: Return
nilfor empty slices. Checklen(s) == 0for emptiness.vardeclared slices are immediately usable.
Expert Guidance
These are recommended practices for readability, maintenance, and performance.
Pointers & Interfaces
- No Interface Pointers: Pass interfaces as values. Use a pointer only if methods must modify the underlying data.
- Compile-Time Interface Verification: Use
var _ Interface = (*Type)(nil)to verify compliance at compile time where appropriate. - Receiver Choice: Pointer receivers are only for pointers or addressable values. Value receivers work for both. Interfaces can be satisfied by pointers even for value receivers.
Concurrency & Synchronization
- Zero-Value Mutexes:
sync.Mutexandsync.RWMutexare valid in their zero-value state. Do not use pointers to mutexes. Use non-pointer fields in structs. - No Mutex Embedding: Do not embed mutexes in structs, even unexported ones.
- Synchronization: Use
sync.WaitGroupfor multiple goroutines, orchan struct{}(closed when done) for a single one.
Time Management
timePackage: Always use the"time"package for all time operations.- Instants vs. Periods: Use
time.Timefor instants andtime.Durationfor periods. - External Systems: Use
time.Time/time.Durationwith external systems. If not possible, useint/float64with unit in the name (e.g.,Millis), or RFC 3339 strings for timestamps. - Comparison: Use
.AddDatefor calendar days,.Addfor absolute 24-hour periods.
Performance (Hot Path Only)
strconvoverfmt: Usestrconvfor primitive-to-string conversions.- String-to-Byte: Convert fixed strings to
[]byteonce and reuse. - Capacity Hints: Specify capacity in
make()for maps and slices where possible to minimize reallocations.
Code Style & Readability
- Line Length: Soft limit of 99 characters. Avoid horizontal scrolling.
- Grouping: Group related
import,const,var, andtypedeclarations. Group variables in functions if declared adjacently. - Import Ordering: Two groups: Standard library first, then others, separated by a blank line.
- Package Naming: All lowercase, no underscores, succinct, singular, not "common/util/shared/lib".
- Function Naming: MixedCaps. Underscores allowed in tests for grouping.
- Import Aliasing: Only if the package name doesn't match the last element of the path or if there is a con
Установить go-uber-style-guide в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл go-uber-style-guide?
Use this skill to write, refactor, or review Go code according to the Uber Go Style Guide. It ensures strict adherence to correctness, safety, and idiomatic patterns.
Как установить скилл go-uber-style-guide?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл go-uber-style-guide запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic