Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

toolchains-golang-core

БесплатноБез исполняемых скриптовНе проверен

Go 1.22-1.24 core patterns for minimalism, efficiency, code reuse, and performance

bobmatnycот bobmatnyc★ 160 звёзд на GitHub

Об этом скилле

Go Core Patterns

Quick Start

  • Accept interfaces, return structs — small interfaces at the consumer site
  • Pre-allocate slices/maps with make([]T, 0, n) / make(map[K]V, n)
  • Wrap errors with %w; check with errors.Is / errors.As
  • Always run go test -race ./... in CI
  • Profile with go tool pprof before optimizing anything

Minimalism Patterns

  • Accept interfaces, return structs — narrow interface params improve testability; concrete return types preserve extensibility
  • Define interfaces at the consumer — the calling package defines what it needs; avoid coupling interface to implementation
  • Keep interfaces small — 1-2 methods; compose with embedding: type ReadWriter interface { Reader; Writer }
  • Functional options for constructors — func WithTimeout(d time.Duration) Option returns a closure; keeps New* signatures stable
  • Unexported option fields — export With* functions, keep struct fields private; one construction path, predictable outcome
  • Constructor naming — NewServer(opts ...Option) *Server; the injection point for interface-typed dependencies
  • Avoid init() side effects — prefer explicit initialization in main() or constructors; init() hides execution order

Efficiency Patterns

  • Pre-allocate slices — make([]T, 0, n) eliminates grow-copy cycles; reduces GC pressure ~30%
  • Pre-allocate maps — make(map[K]V, n) avoids rehashing; over-estimate rather than under-estimate
  • strings.Builder over + — internal []byte buffer; call b.Grow(n) to pre-size before writing
  • sync.Pool for short-lived objects — reuse buffers, byte slices, response structs; always reset before returning to pool
  • Avoid any / interface{} in hot paths — boxing causes heap allocation and dynamic dispatch; use concrete types or generics
  • strconv over fmt.Sprintf in hot paths — fmt arguments escape to heap; strconv.Itoa, AppendInt stay on stack
  • Value receivers for small immutable types — no pointer indirection; both T and *T satisfy value-receiver methods
  • Pointer receivers for large structs or mutation — avoids copying; be consistent within a type (all pointer or all value)
  • Return values not pointers for small types — keeps allocation on stack; reduces GC pressure in tight loops
  • Move loop-invariant work outside loops — constant calculations inside hot loops multiply with iteration count

Code Reuse

  • Generics: any for store/pass only — no operations needed; suitable for containers like Stack[T any]
  • Generics: comparable for equality — required for map keys, sets, Contains(); any does not satisfy comparable
  • Generics: constraints.Ordered for comparisons — covers int, float, string; needed for sort, min, max helpers
  • Generics: prefer function params over method constraints — pass cmp func(T, T) int rather than requiring a Compare method
  • Generics: start concrete, genericize on duplication — add type params only when the same logic repeats for multiple types
  • Embed structs for implementation reuse — promoted fields and methods; override selectively; avoid deep embedding chains
  • Domain packages over layer packages — internal/user/, internal/order/ not internal/handlers/, internal/services/
  • No catch-all utils packages — every package has a focused purpose; move helpers into the domain that owns them

Modern Go (1.22-1.23)

  • Range over integers (1.22) — for i := range 10 replaces for i := 0; i < 10; i++
  • Loop variable fix (1.22) — each iteration creates new variables; closure capture bugs eliminated
  • Enhanced ServeMux (1.22) — "GET /items/{id}" registers method + wildcard; r.PathValue("id") extracts segments
  • Wildcard catch-all (1.22) — "/files/{path...}" matches remaining path; must appear at end of pattern
  • Request.Pattern (1.23) — matched pattern available on the request for logging and observability
  • Range over function iterators (1.23) — func(func(K, V) bool) as range expressions; stable in 1.23
  • iter package (1.23) — iter.Seq[V] and iter.Seq2[K, V] standard types; foundation for custom iterators
  • slices / maps iterators (1.23) — slices.All, slices.Collect; maps.Keys, maps.Values, maps.Collect
  • unique package (1.23) — canonical interning of comparable values; deduplication and memory savings
  • slog for structured logging — JSON handler in prod, text in dev; slog.SetDefault bridges legacy log.Printf calls
  • Contextual log fields — pass request_id, user_id, trace_id via slog.With() to correlate log lines
  • LogValuer for sensitive types — redact PII; skips expensive computation when log level is disabled

Modern Go (1.24)

  • tool directive in go.mod (1.24) — track executable dependencies natively; go get -tool adds them, go tool <name> runs them. Replaces the old blank
Полный SKILL.md на GitHub

Установить toolchains-golang-core в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл toolchains-golang-core?

Go 1.22-1.24 core patterns for minimalism, efficiency, code reuse, and performance

Как установить скилл toolchains-golang-core?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл toolchains-golang-core запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить toolchains-golang-core с