Skip to main content

chainsafe-go-developer

Idiomatic Go development at ChainSafe — implementation-level guidance for writing Go code in Gossamer and other Go projects. Use this skill whenever the user is writing Go code, asking how to do something in Go, debugging Go, picking between Go patterns at the line/function level, setting up Go tooling, configuring golangci-lint, writing Go tests, mocking interfaces in Go, dealing with context propagation, structuring errors with %w, or any other concrete Go coding task. EVEN IF the user does not say "Go" explicitly but the file in scope is .go. Triggers on "write a Go function", "implement in Go", "how do I X in Go", "fix this Go code", "test this Go function", "mock this interface", "lint my Go", "Go CI setup", "context handling", "gomock", "table-driven test", "%w vs %v", "error wrapping in Go", ".golangci.yml". Do NOT use for Go architectural design (use chainsafe-go-architect) or Go PR review (use chainsafe-go-reviewer).

설치로 이동

소스 정보

저장소
ChainSafe/engineering-handbook
최근 소스 활동
2026년 7월 20일 11:44
감지된 SKILL.md 언어
영어
스타
7
포크
1

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
chainsafe-go-developer
description
Idiomatic Go development at ChainSafe — implementation-level guidance for writing Go code in Gossamer and other Go projects. Use this skill whenever the user is writing Go code, asking how to do something in Go, debugging Go, picking between Go patterns at the line/function level, setting up Go tooling, configuring golangci-lint, writing Go tests, mocking interfaces in Go, dealing with context propagation, structuring errors with %w, or any other concrete Go coding task. EVEN IF the user does not say "Go" explicitly but the file in scope is .go. Triggers on "write a Go function", "implement in Go", "how do I X in Go", "fix this Go code", "test this Go function", "mock this interface", "lint my Go", "Go CI setup", "context handling", "gomock", "table-driven test", "%w vs %v", "error wrapping in Go", ".golangci.yml". Do NOT use for Go architectural design (use chainsafe-go-architect) or Go PR review (use chainsafe-go-reviewer).
metadata
{"type":"role-workflow","language":"go","role":"developer","source":"languages/go/developer.md","authored-via":"anthropic-skills:skill-creator (2026-05-27)"}
# Go Developer Idiomatic Go implementation at ChainSafe. The full reference is [`languages/go/developer.md`](../../languages/go/developer.md); load that file for complete guidance. This skill is the operational summary. ## Tooling baselines - **Linter:** [`golangci-lint`](https://golangci-lint.run/) pinned to a specific version in CI. Use `.golangci.yml` at repo root. - **Mocking:** `golang/mock` (gomock). Per-package, kept in `mocks_test.go` (generated) + `mocks_generate_test.go` (the `//go:generate` directive). Never export mocks. - **Modules:** `go.mod` + `go.sum` committed; `go.sum` never edited by hand. - **Race detector:** `go test -race` in CI for any package touching concurrency. ## Mock discipline (most-flagged in review) - **No `gomock.Any()`.** Use concrete arguments or custom matchers. - **No `.AnyTimes()`.** State exact call counts. - **Always set `.Return(...)`** for functions that return. - For subtests, build a fresh `gomock.NewController(t)` per subtest. Mocks built from parent `t` leak between subtests. - Use functional mock builders (`func(ctrl *gomock.Controller) Fetcher`) for table-driven tests with mocks. ## Argument passing - **Default to pass-by-value.** Reduces nil-risk; clearer behavior. - **Slices:** by value if you mutate elements; `*[]T` only to change slice length. - **Maps, channels, most interfaces:** always by value (pointers under the hood). - **Structs:** by value if performance allows; by pointer if you need to mutate non-pointer fields or if >80 bytes. - **Mutexes:** always by pointer. ## Panic - `panic` is **only** for programmer error — impossible states, sentinel-invariant violation, default switch on enum. - I/O errors, network errors, parse failures, user input — return `error`. Never panic. - `recover` only in test code (`assert.PanicsWithValue`). ## Context ```go func DoThing(ctx context.Context, arg T) (Result, error) { ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() // ... } ``` `ctx` is the first parameter. Always. Never `context.TODO()` in committed code. Pass `ctx` down; do not store in structs except in narrow framework cases. Every external call — network, database, stream read — gets an explicit deadline via `context.WithTimeout` (or a socket/read deadline where `ctx` isn't threaded through). An inherited `ctx` with no deadline is not a timeout. ## Errors ```go data, err := fetch(ctx, url) if err != nil { return fmt.Errorf("fetching %s: %w", url, err) } ``` - `%w` to preserve the chain. - Lowercase first letter, no trailing punctuation. - Context before the error: `"fetching %s: %w"`, not `"%w while fetching"`. - Callers use `errors.Is` / `errors.As`. ## Testing - Table-driven tests for >1 case. Map-keyed for free naming; subtests for isolation. - `t.Parallel()` when tests don't share mutable state. - `go test -race ./...` for race-sensitive packages. ## CI baseline - `go vet ./...` - `gofmt -l .` → no output - `golangci-lint run` - `go test -race ./...` - `go build ./...` - Mocks regenerated; `git diff --exit-code` confirms no drift. ## Anti-patterns - `panic` for non-fatal errors. - Goroutines without `context.Context`. - `init()` connecting to external services. - `interface{}` / `any` parameters (use generics where possible). - Mocks with `gomock.Any()`. - Package-level mutable state. ## Related - Full reference: [`languages/go/developer.md`](../../languages/go/developer.md) - Idioms cheat sheet: [`languages/go/idioms.md`](../../languages/go/idioms.md) - Gotchas: [`languages/go/gotchas.md`](../../languages/go/gotchas.md) - Sister roles: `chainsafe-go-architect`, `chainsafe-go-reviewer` - Workflow: `chainsafe-research-plan-implement`
GitHub에서 보기