本文へ移動
cccskills
無料GitHub で公開

go

Idiomatic programming style, patterns, and conventions for Go (Golang) development. Trigger when: - Writing, refactoring, reviewing, or debugging Go code. - Files matching the pattern **/*.go (including go.mod, go.sum) are in the workspace or referenced. - Tasks involve: go fmt, go test, go build, go vet, golangci-lint. - Prompt contains keywords: go, golang, goroutine, channel, select, interface, err != nil, defer, panic, gofmt, struct.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md8.2 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Go Language Idioms

Go favors simplicity, readability, and explicit behavior. Work with the language's conventions, not against them.


Core Philosophy

  • Simplicity over cleverness — clear, boring code is better than clever, obscure code
  • Explicit over implicit — errors are values, not exceptions
  • Composition over inheritance — embed types, implement interfaces
  • Share by communicating — don't communicate by sharing memory

Formatting

Let gofmt handle it. Don't fight the formatter.

gofmt -w .        # Format all files
go fmt ./...      # Format package

All Go code in the ecosystem follows gofmt. There is no debate.


Naming

General Rules

ScopeStyleExample
ExportedPascalCaseReadFile, HTTPClient
UnexportedcamelCasereadFile, httpClient
Packageslowercase, single wordbytes, http, bufio
AcronymsAll capsHTTP, URL, ID (not Http, Url, Id)

Package Names

  • Short, concise, evocative
  • No underscores or mixedCaps
  • The package name is part of the type name: bufio.Reader, not bufio.BufReader

Getters and Setters

// ❌ Don't prefix getters with "Get"
func (u *User) GetName() string

// ✅ Just use the field name
func (u *User) Name() string

// ✅ Setters use "Set" prefix
func (u *User) SetName(name string)

Interface Names

One-method interfaces use method name + -er suffix:

MethodInterface
ReadReader
WriteWriter
CloseCloser
StringStringer

Functions

Multiple Return Values

Go functions return (result, error) instead of throwing:

func ReadFile(path string) ([]byte, error) {
    f, err := os.Open(path)
    if err != nil {
        return nil, err
    }
    defer f.Close()
    return io.ReadAll(f)
}

Named Return Values

Use for documentation, but avoid naked returns in non-trivial functions:

// Named returns document what's being returned
func ParseDuration(s string) (duration time.Duration, err error) {
    // ...
    return duration, nil  // Explicit, not naked
}

Defer

Use defer for cleanup. Defers execute LIFO at function exit:

func CopyFile(dst, src string) error {
    r, err := os.Open(src)
    if err != nil {
        return err
    }
    defer r.Close()

    w, err := os.Create(dst)
    if err != nil {
        return err
    }
    defer w.Close()

    _, err = io.Copy(w, r)
    return err
}

Interfaces

Keep Interfaces Small

Accept interfaces, return concrete types:

// ✅ Function accepts interface (flexible)
func Process(r io.Reader) error

// ✅ Function returns concrete type (useful)
func NewClient() *Client

Interface Satisfaction

Interfaces are satisfied implicitly—no implements keyword:

type Stringer interface {
    String() string
}

type User struct{ Name string }

// User satisfies Stringer automatically
func (u User) String() string {
    return u.Name
}

Compile-Time Check

Verify interface satisfaction at compile time:

var _ io.Reader = (*MyReader)(nil)

Pointers vs. Values

When to Use Pointer Receivers

Use PointerWhen
*TMethod modifies the receiver
*TStruct is large (avoid copying)
*TConsistency (if any method uses pointer, all should)

When to Use Value Receivers

Use ValueWhen
TMethod doesn't modify receiver
TType is small (int, small struct)
TType is immutable by design

Concurrency

Goroutines

Lightweight, start with go:

go func() {
    // runs concurrently
}()

Channels

Use channels for communication between goroutines:

ch := make(chan int)       // Unbuffered
ch := make(chan int, 100)  // Buffered

ch <- value   // Send
v := <-ch     // Receive

Share by Communicating

"Don't communicate by sharing memory; share memory by communicating."

// ❌ Shared state with mutex
var count int
var mu sync.Mutex

// ✅ Channel-based coordination
type result struct{ value int }
results := make(chan result)

Common Patterns

PatternUse Case
sync.WaitGroupWait for N goroutines to complete
context.ContextCancellation and timeouts
selectMultiplex channel operations
sync.OnceOne-time initialization

Error Handling

Errors Are Values

Check explicitly. Never discard with _:

// ❌ Never ignore errors
result, _ := doSomething()

// ✅ Always check
result, err := doSomething()
if err != nil {
    return fmt.Errorf("doing something: %w", err)
}

Error Wrapping

Use %w to wrap errors with context:

if err != nil {
    return fmt.Errorf("failed to parse config %s: %w", path, err)
}

Custom Errors

For libraries, define sentinel errors or custom types:

// Sentinel errors
var ErrNotFound = errors.New("not found")

// Custom error types
type ValidationError struct {
    Field   string
    Message string
}

func (e *ValidationError) Error() string {
    return fmt.Sprintf("%s: %s", e.Field, e.Message)
}

When to Panic

ContextPanic?Alternative
Library code❌ NeverReturn error
Impossible states✅ AcceptableAssert invariants
Init failures✅ Acceptablelog.Fatal

Anti-Patterns

Anti-PatternDescriptionRemedy
Ignoring errorsUsing _ to discard errorsAlways check or explicitly document why ignored
Naked returnsreturn without values in complex functionsUse explicit return values
Interface pollutionDefining interfaces before neededDefine interfaces at point of use
Premature channelsUsing channels when mutex sufficesStart simple; add concurrency primitives as needed
Giant interfacesInterfaces with many methodsKeep interfaces small; compose when needed

Tooling

go fmt ./...           # Format code
go vet ./...           # Static analysis
golangci-lint run      # Comprehensive linting
go test ./...          # Run tests
go test -race ./...    # Detect race conditions

Quick Reference

  • Errors are values — check explicitly, wrap with context
  • Accept interfaces, return structs — flexible inputs, concrete outputs
  • Use gofmt — no formatting debates
  • Prefer composition — embed types, small interfaces
  • Channels for coordination — share by communicating
  • defer for cleanup — runs at function exit, LIFO
  • No naked returns — be explicit in non-trivial functions

These idioms refine but are subordinate to the Code-Edit Constraints.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

ai-audit

無料

SOP for auditing AI-generated code. Trigger when: - Reviewing, refactoring, or cleaning up AI-generated code to prevent regressions or hallucinated APIs. - Prompt contains: /ai-audit, code audit, AI cleanup, common flaws.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

api-audit

無料

Protocol for auditing API surface coherence and type safety. Trigger when: - Evaluating API designs, interface type safety, or design elegance. - Prompt contains: /api-audit, API surface, API coherence, type safety.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

boundary

無料

Normative sufficiency conditions for Initial Boundary Conditions (IBCs) and the SOP for the cheap-tier boundary refinement loop (/boundary). Trigger when: - Crafting, auditing, or refining a prompt/IBC destined for an expensive (architect-class) model or an autonomous worker dispatch. - Evaluating whether a task frame is sufficient to bound an agent walk. - Prompt contains: /boundary, IBC, initial boundary condition, boundary contract, sufficiency conditions, worker prompt, prompt refinement.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

campaign

無料

SOP for the architect-tier campaign workflow (/campaign): exhaustive survey, mitigation planning, tiered orchestration, and reconciliation. Trigger when: - Running a multi-workstream initiative where an expensive architect-tier council surveys, plans, emits worker prompts, and judges landed work. - Conducting production-readiness assessments that fan out into autonomous mitigation dispatches across model tiers. - Prompt contains: /campaign, campaign workflow, survey, orchestrate, reconcile, premise freshness, tier routing, worker IBC, scratch.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

chronicle

無料

Maintain and update the persistent project chronicle (docs/chronicle.md). Trigger when: - The human requests a history summary or chronicle update. - Starting work on a new codebase and needing context on its evolution. - Prompt contains keywords: /chronicle, chronicle, project history, git log summary, history summary.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

Rules, conventions, and constraints for formatting git commit messages and committing at logical boundaries. Trigger when: - Drafting, revising, or validating git commit messages. - Pausing at commit boundaries under the CORE or CONTINUE workflows. - Evaluating whether a changeset should be split into multiple commits. - Prompt contains keywords: commit message, git commit, conventional commits, commit hygiene, commit guidelines, logical boundary, spaghetti diff, atomic commit, commit boundary.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

nrdxp のスキルをすべて見る

このスキルの問題を報告する