用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/bobmatnyc/claude-mpm --skill toolchains-golang-core命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | toolchains-golang-core |
| description | Go 1.22-1.24 core patterns for minimalism, efficiency, code reuse, and performance |
| version | 1.1.0 |
| category | toolchains-golang |
| tags | ["golang","go","patterns","performance","minimalism","efficiency"] |
| effort | medium |
make([]T, 0, n) / make(map[K]V, n)%w; check with errors.Is / errors.Asgo test -race ./... in CIgo tool pprof before optimizing anythingtype ReadWriter interface { Reader; Writer }func WithTimeout(d time.Duration) Option returns a closure; keeps New* signatures stableWith* functions, keep struct fields private; one construction path, predictable outcomeNewServer(opts ...Option) *Server; the injection point for interface-typed dependenciesinit() side effects — prefer explicit initialization in main() or constructors; init() hides execution ordermake([]T, 0, n) eliminates grow-copy cycles; reduces GC pressure ~30%make(map[K]V, n) avoids rehashing; over-estimate rather than under-estimatestrings.Builder over + — internal []byte buffer; call b.Grow(n) to pre-size before writingsync.Pool for short-lived objects — reuse buffers, byte slices, response structs; always reset before returning to poolany / interface{} in hot paths — boxing causes heap allocation and dynamic dispatch; use concrete types or genericsstrconv over fmt.Sprintf in hot paths — fmt arguments escape to heap; strconv.Itoa, AppendInt stay on stackT and *T satisfy value-receiver methodsany for store/pass only — no operations needed; suitable for containers like Stack[T any]comparable for equality — required for map keys, sets, Contains(); any does not satisfy comparableconstraints.Ordered for comparisons — covers int, float, string; needed for sort, min, max helperscmp func(T, T) int rather than requiring a Compare methodinternal/user/, internal/order/ not internal/handlers/, internal/services/utils packages — every package has a focused purpose; move helpers into the domain that owns themfor i := range 10 replaces for i := 0; i < 10; i++ServeMux (1.22) — "GET /items/{id}" registers method + wildcard; r.PathValue("id") extracts segments"/files/{path...}" matches remaining path; must appear at end of patternRequest.Pattern (1.23) — matched pattern available on the request for logging and observabilityfunc(func(K, V) bool) as range expressions; stable in 1.23iter package (1.23) — iter.Seq[V] and iter.Seq2[K, V] standard types; foundation for custom iteratorsslices / maps iterators (1.23) — slices.All, slices.Collect; maps.Keys, maps.Values, maps.Collectunique package (1.23) — canonical interning of comparable values; deduplication and memory savingsslog for structured logging — JSON handler in prod, text in dev; slog.SetDefault bridges legacy log.Printf callsrequest_id, user_id, trace_id via slog.With() to correlate log linesLogValuer for sensitive types — redact PII; skips expensive computation when log level is disabledtool directive in go.mod (1.24) — track executable dependencies natively; go get -tool adds them, go tool <name> runs them. Replaces the old blank-import tools.go workaroundtype Set[T comparable] = map[T]struct{} now parameterizable like defined types; alias generic instantiations without re-declaringmap to a Swiss Tables implementation; measurable improvement on map-heavy workloads and faster large-map access with no code changesweak package + runtime.AddCleanup (1.24) — weak.Pointer[T] for caches/canonicalization maps that must not pin memory; AddCleanup supersedes SetFinalizer (multiple cleanups, interior pointers, no leak cycles)os.Root directory jail (1.24) — os.OpenRoot(dir) confines all subsequent Open/Create to that subtree; prevents path-traversal escapes in untrusted file handlingtesting.B.Loop() (1.24) — for b.Loop() replaces the for range b.N benchmark idiom; keeps args alive and runs setup once, removing a class of benchmark mistakestesting/synctest (1.24, experimental) — fake-clock virtual time + goroutine-blocking detection for deterministic concurrency tests; gate behind GOEXPERIMENT=synctestT.Context / T.Chdir (1.24) — per-test context auto-cancelled at test end; per-test working directory restored on cleanup; prefer over manual context.WithCancel + defer os.Chdirslog.DiscardHandler (1.24) — drop-in no-op handler; cleaner than slog.New(slog.NewTextHandler(io.Discard, nil)) for silencing logs in testsgo tool pprof for CPU, heap, mutex, goroutine; never optimize without measurement datainuse_space for leak detection — alloc_space is lifetime total; inuse_space is currently retained memorygo build -gcflags="-m" shows heap escapes; target hot-path allocationsfieldalignment linter to verifyerrgroup for fan-out — golang.org/x/sync/errgroup propagates first error and waits for all goroutines; replaces manual WaitGroup + error channelcontext.Context; check ctx.Done() in goroutine loops to prevent leakst.Run — named subtests allow selective execution with -run TestFoo/case_namet.Parallel() inside t.Run reduces suite runtime ~30-40%; ensure no shared mutable statetestify/require for setup, assert for checks — require stops immediately on failure; assert continues and collects failureshttptest.NewServer — real HTTP on localhost; tests full request/response cycle without mocking transportf.Add(seed) then f.Fuzz(func(t *testing.T, s string){...}); run with -fuzz flag and -fuzztime in CItestcontainers-go — spin up real Postgres, Redis, or any Docker image during integration testsgoleak.VerifyNone(t) — fails if goroutines survive after test completes; catches goroutine leaks early-race — go test -race ./... in CI; required for all concurrent codet.Cleanup — registered functions run LIFO after test; prefer over manual defer teardown%w — fmt.Errorf("load config: %w", err) preserves chain for errors.Is / errors.Aserrors.Is for sentinel checks — traverses wrapping chain; replaces direct err == ErrNotFound comparisonerrors.As for typed extraction — var e *APIError; errors.As(err, &e) pulls typed error from any depthvar ErrNotFound = errors.New("not found"); exported for expected recoverable conditionsError() string and Unwrap() error; carry HTTP status, codes, metadataif err != nil right after the call; early return; no deep nestingerrors.Join for concurrent errors — since Go 1.20; collect multiple goroutine errors into one returned valuedefer func() { if r := recover(); r != nil { log... } }() prevents cascade crashesrange over a channel blocks forever if sender never closes; always close from the senderselect with ctx.Done()select with context so goroutines can exittime.Sleep for synchronization — use sync.WaitGroup, channels, or context; Sleep is a race conditionsync.Mutex / sync.WaitGroup — always pass by pointer; copying creates an independent, incorrect lockinit() with side effects — database connections, file reads, HTTP calls in init() make testing and reuse impossiblereturn obscure flow in functions longer than ~5 linesutils / common / helpers packages — signals unclear ownership; split into domain-specific packages instead