К основному содержанию
скилл CX Codex

go-coding-standards — скилл для Claude Code: обзор и установка

Скилл задаёт для ассистента правила оформления Go-кода на базе Effective Go. Он помогает выстроить порядок импортов, теги структур и ранние возвраты при ревью или написании кода.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add eduardo-sl/go-agent-skills --skill go-coding-standards -a claude-code
Открыть на GitHub

Что делает go-coding-standards

Инструкция задаёт единые правила для написания и ревью Go-кода. Скилл опирается на Effective Go и Go Code Review Comments. Он требует именовать поля при инициализации структур, группировать импорты в три блока и избегать лишних else через ранние возвраты. Для перечислений нулевое значение резервируется под Unknown через iota. Мягкое ограничение длины строки составляет 99 символов.

Внутри скилла заложены ссылки на детальные руководства references/file-organization.md и references/receivers-and-tags.md. Ассистент использует системные утилиты go, gofmt и golangci-lint, а также поиск по файлам. Без установленного Go toolchain скилл работать не сможет. Линтер golangci-lint остаётся опциональным.

Этот набор правил не решает вопросы архитектуры, конкурентности или профилирования. Нейминг вынесен в отдельный скилл go-naming, поэтому здесь запрещено только переопределение встроенных идентификаторов вроде len или error. Проверка кода считается завершённой лишь тогда, когда goimports и go vet отрабатывают без единой ошибки.

Какие задачи решает

  • Упорядочить импорты по стандартным, внешним и внутренним пакетам
  • Убрать лишнюю вложенность условий с помощью ранних возвратов
  • Проверить инициализацию структур с именованием полей без позиционных литералов
  • Настроить единый тип ресиверов для методов конкретной структуры
  • Расставить корректные теги сериализации с проверкой через go vet

Примеры запросов агенту

  • Проверь стиль Go в internal/service/user.go и убери лишние else-блоки
  • Приведи импорты и инициализацию структур к соглашениям Go
  • Проверь ресиверы и теги сериализации перед запуском go vet

Как установить go-coding-standards

1Через Skills CLI (Vercel)

npx skills add eduardo-sl/go-agent-skills --skill go-coding-standards -a claude-code

2Вручную: положить файлы

~/.claude/skills/go-coding-standards/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/go-coding-standards/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о go-coding-standards

Как установить go-coding-standards в Claude Code?

Выполните команду npx skills add eduardo-sl/go-agent-skills --skill go-coding-standards -a claude-code. Ассистент добавит скилл в проект и сможет вызывать его при анализе Go-файлов.

Что делает скилл go-coding-standards?

Он настраивает правила оформления кода: упорядочивание импортов, работу с defer, объявление переменных и правильный выбор ресиверов. Скилл также следит за уменьшением вложенности через ранние возвраты.

Какие инструменты нужны для работы скилла?

Обязательно требуется установленный Go toolchain с утилитами go и gofmt. Линтер golangci-lint поддерживается, но его наличие необязательно.

Исходный текст

SKILL.md · MIT
---
name: go-coding-standards
description: >
  Go coding standards and style conventions grounded in Effective Go, Go
  Code Review Comments, and production-proven idioms. Use when writing or
  reviewing Go code for import ordering, variable declarations, struct
  initialization, nesting, receivers, struct tags, or formatting rules.
  Trigger examples: "check Go style", "fix formatting", "Go conventions",
  "struct initialization".
  Not for: naming (go-naming), architecture (go-architecture-review),
  concurrency (go-concurrency-review), performance tuning
  (go-performance-review).
user-invocable: true
license: MIT
compatibility: Designed for Claude Code or similar AI coding agents working on Go projects. Requires the Go toolchain. golangci-lint is optional.
allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(gofmt:*) Bash(golangci-lint:*)
metadata:
  author: eduardo-sl
  version: "2.0.0"
---

# Go Coding Standards

Idiomatic Go conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms.
All code MUST pass `goimports`, `go vet`, and `staticcheck` (or `golangci-lint run`) without errors.

> Community default. A project skill or agent-config rule that explicitly
> supersedes `go-coding-standards` takes precedence over this one.

Detailed reference material, loaded on demand:

- `references/file-organization.md` — declaration grouping, file order,
  breaking long signatures.
- `references/receivers-and-tags.md` — receiver consistency and struct tag
  examples.

Read a reference file only when the summary below is not enough.

## 1. Import Ordering

Group imports in this order, separated by blank lines:

```go
import (
    // 1. Standard library
    "context"
    "fmt"
    "log/slog"
    "net/http"

    // 2. External packages
    "github.com/gorilla/mux"

    // 3. Internal/project packages
    "github.com/myorg/myproject/internal/service"
)
```

NEVER use dot imports. Use aliasing only to resolve conflicts.

## 2. Naming

Naming is owned by the go-naming skill: packages, stuttering, initialisms,
getters, receivers, error and test names. Two rules stay here because they
are about declarations: do not shadow predeclared identifiers (`len`,
`new`, `error`, `min`, `max`), and unexported package-level variables may
carry a `_` prefix (`_defaultTimeout`) when the codebase uses that
convention.

## 3. Variable Declarations

### Top-level
Use `var` for top-level declarations. Do NOT specify type when it matches the expression:

```go
// ✅ Good
var _defaultPort = 8080
var _logger = slog.Default()

// ❌ Bad — redundant type
var _defaultPort int = 8080
```

### Local
- Prefer `:=` for local variables.
- Use `var` only when zero-value initialization is intentional and meaningful.

```go
// ✅ Good — zero value is meaningful
var buf bytes.Buffer

// ✅ Good — short declaration
name := getUserName()
```

## 4. Struct Initialization

ALWAYS use field names, and omit zero-value fields unless they carry
meaning — positional literals break silently when fields are added or
reordered:

```go
// ✅ Good
user := User{Name: "Alice", Email: "[email protected]"}

// ❌ Bad — positional
user := User{"Alice", "[email protected]", 0}
```

## 5. Reduce Nesting

Handle errors and special cases first with early returns, so the happy
path stays at the left margin. Drop an `else` whose `if` already returns,
and prefer assign-default-then-override:

```go
// ✅ Good — guard clauses; no else
for _, v := range data {
    if !v.IsValid() {
        continue
    }
    if err := v.Process(); err != nil {
        return fmt.Errorf("process %s: %w", v.ID, err)
    }
}

a := 10 // default, then override
if condition {
    a = 20
}
```

## 6. Grouping and Ordering

- Group related `const` and `var` declarations in one parenthesized block.
- File order: constants and variables, constructors, exported methods
  (by importance, not alphabetically), unexported methods, helpers.
- Methods sit directly after the type they belong to.

## 7. Line Length

Soft limit of 99 characters. Break a long signature one parameter per
line, closing parenthesis on its own line. Examples:
`references/file-organization.md`.

## 8. Defer Usage

Use `defer` for cleanup. It makes intent clear at the point of acquisition:

```go
mu.Lock()
defer mu.Unlock()

f, err := os.Open(path)
if err != nil {
    return fmt.Errorf("open %s: %w", path, err)
}
defer f.Close() // read-only; check Close errors on files you write
```

## 9. Enums

Reserve the zero value for an explicit `Unknown` sentinel, so a value that
was never set cannot pass for a real state:

```go
type Status int

const (
    StatusUnknown Status = iota
    StatusActive
    StatusInactive
)
```

## 10. Use `time` Package Properly

- Use `time.Duration` for durations, NOT raw integers.
- Use `time.Time` for instants. Use `time.Since(start)` instead of `time.Now().Sub(start)`.
- When a format cannot carry a `time.Duration` (JSON, YAML), put the unit
  in the field name — `TimeoutSeconds int` — and convert at the edge.

```go
// ✅ Good
func poll(interval time.Duration) { ... }
poll(10 * time.Second)

// ❌ Bad
func poll(intervalSecs int) { ... }
poll(10)
```

## 11. Receivers

Pick one receiver kind per type and use it on every method — a mixed
method set changes with how the value is held. Use a pointer receiver if
any method mutates, the struct holds a `sync.Mutex` or other no-copy
field, the struct is large, or another method already needs a pointer.
Use a value receiver for small immutable types. Name the receiver one or
two letters after the type (`s *Server`), the same on every method, never
`this` or `self`. Examples: `references/receivers-and-tags.md`.

## 12. Struct Tags

The compiler does not check tags, so a typo is silent.

- Tag every field of a type that crosses a serialization boundary, even
  when the name already matches.
- `json:"-"` for anything that must never leave the process — an
  unexported field is skipped silently, which reads as an oversight.
- `omitempty` cannot tell "absent" from "zero"; use a pointer or wrapper
  when that distinction matters. `omitempty` never omits a struct — use
  `omitzero` (Go 1.24+), which honors the Go zero value and `IsZero()`, for
  fields like `time.Time`.
- Run `go vet` — its `structtag` check catches malformed tags.

## 13. Function Shape

- Name the parts of a condition with three or more operands (`isOwner`,
  `isAdmin`) so the `if` reads as the business rule.
- `ctx context.Context` first, then inputs, then options.
- More than about four parameters, or several of one type next to each
  other, means an options struct or functional options — the
  go-design-patterns skill owns both.
- Naked returns only in functions short enough to see every return value.

## Verification Checklist

Before considering code complete:
1. `goimports` runs clean
2. `go vet ./...` passes
3. `golangci-lint run` passes (if configured)
4. No shadowed built-in identifiers
5. All imports properly grouped and ordered
6. Struct initializations use field names
7. No unnecessary nesting or else blocks
8. Receiver kind is consistent across every method on a type
9. Every serialised struct field carries an explicit tag

© eduardo-sl · MIT · eduardo-sl/go-agent-skills

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

Все скиллы по теме «Языки программирования» →
migrate-to-shoehorn Matt Pocock Переводит type assertions с as в тестах на функции из @total-typescript/shoehorn. Нужен для частичных объектов и намеренно неверных данных в проверках. 475 388установок write-swift emilkowalski Скилл помогает писать, проверять и переносить код на Swift с учётом модели языка. Подойдёт, когда нужно разобраться с конкурентностью, ошибкой или циклом удержания объектов. CX Codex +1 119 300установок megacave JuliusBrussee Переводит ответы ассистента на классический китайский язык (вэньянь) для экономии места на экране. Активируется командами /megacave или /caveman wenyan. CX Codex +1 25 400установок find-docs upstash Тянет актуальную документацию, справочники API и примеры кода для любой библиотеки через Context7 CLI. Пригодится, когда агент отвечает по устаревшим данным обучения. CX Codex +1 9 400установок typescript-advanced-types Seth Hobson Помогает агенту писать сложную типизацию TypeScript: generics, conditional types и преобразования типов. Нужен для библиотек, API-клиентов и строгих конфигураций. CX Codex 92 169установок smart-explore thedotmack Структурно ищет функции и классы через tree-sitter. Пригодится, когда нужно разобраться в кодовой базе без чтения всех файлов. CX Codex +1 7 300установок

Из того же набора34

go-error-handling Скилл задаёт агенту правила работы с ошибками в Go: обёртка через %w, sentinel-ошибки, свои типы и errors.Is/errors.As. CX Codex +1 ★ 83звёзд репо go-documentation Скилл настраивает оформление комментариев godoc, тестовых примеров и файлов документации для Go-проектов. Помогает агенту следовать соглашениям Go 1.19+ без лишнего шума в коде. CX Codex +1 ★ 83звёзд репо go-data-structures Скилл помогает выбирать и безопасно использовать слайсы, карты и массивы в Go. Пригодится, когда нужно разобраться с append, nil-слайсами или порядком обхода карты. CX Codex +1 ★ 83звёзд репо go-context Скилл для ИИ-агента, который проверяет и правит работу с context.Context в Go: отмена, таймауты, значения, типичные ошибки. CX Codex +1 ★ 83звёзд репо go-code-review Скилл проверяет Go-код и PR по структурированному списку: от обработки ошибок до тестов. Запускайте его перед слиянием изменений или для ревью пакета. CX Codex +1 ★ 83звёзд репо go-project-layout Подсказывает, как разложить новый Go-проект по папкам: cmd/, internal/, плоская раскладка для мелких утилит. Пригодится в самом начале, когда структура ещё не сложилась. CX Codex +1 ★ 83звёзд репо go-openapi Настраивает подход spec-first для REST API на Go: генерирует интерфейсы через oapi-codegen, подключает middleware валидации и отслеживает ломающие изменения схемы. CX Codex +1 ★ 83звёзд репо go-interface-design Скилл помогает проектировать интерфейсы Go, разделять зависимости и проверять контракты на этапе компиляции. Пригодится при рефакторинге и подготовке к тестированию. CX Codex +1 ★ 83звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой