From go-backend-skills
Modern Go idioms (1.22–1.26). Use when writing or reviewing Go code. Trigger when you see outdated patterns like `interface{}`, `wg.Add(1)`, `sync.Once`, manual loops that `slices`/`maps` can replace, `errors.As` instead of `errors.AsType`, `context.Background()` in tests, or any pre-1.22 Go pattern.
How this skill is triggered — by the user, by Claude, or both
Slash command
/go-backend-skills:modern-goThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use modern idioms. Never use outdated patterns when a modern alternative exists.
Use modern idioms. Never use outdated patterns when a modern alternative exists.
| Instead of | Use |
|---|---|
fmt.Sprintf for simple string appends | + concat or strings.Join; strings.Builder (with Grow) for loops |
interface{} | any |
err == target | errors.Is(err, target) |
var tErr *MyError; errors.As(err, &tErr) | tErr, ok := errors.AsType[*MyError](err) |
| multiple returns for combined error | errors.Join(err1, err2) |
fmt.Errorf("…: %s", err) | fmt.Errorf("…: %w", err) (wrap with %w) |
time.Now().Sub(start) | time.Since(start) |
deadline.Sub(time.Now()) | time.Until(deadline) |
[]byte(fmt.Sprintf(…)) | fmt.Appendf(buf, …) |
strings.Index + slice | strings.Cut / CutPrefix / CutSuffix |
strings.Clone for copies | strings.Clone(s) / bytes.Clone(b) |
| manual loop to find/sort/filter | slices.* (Contains, Index, IndexFunc, SortFunc, Sort, Compact, Clip, Clone, Reverse, Min, Max) |
| manual map iteration to clone | maps.Clone(m), maps.Copy(dst, src), maps.DeleteFunc |
for k := range m { keys = append(…) } | slices.Collect(maps.Keys(m)) or slices.Sorted(maps.Keys(m)) |
| if/else for first non-zero | cmp.Or(a, b, "default") |
| if/else for min/max of two values | min(a, b) / max(a, b) (builtins) |
| manual loop to delete map entries / zero slice elements | clear(m) deletes all map entries, clear(s) zeros slice elements |
for i := 0; i < n; i++ | for i := range n |
| loop var capture workaround | not needed — loop vars are per-iteration since 1.22 |
sync.Once + wrapper | sync.OnceFunc / sync.OnceValue |
wg.Add(1) + go func(){ defer wg.Done(); … }() | wg.Go(func(){ … }) |
atomic.StoreInt32 / atomic.LoadInt32 | atomic.Bool / atomic.Int64 / atomic.Pointer[T] |
context.WithCancel(context.Background()) in tests | t.Context() |
context.WithCancel + separate error variable | context.WithCancelCause — use cancel(err) then context.Cause(ctx) |
go func(){ <-ctx.Done(); cleanup() }() | stop := context.AfterFunc(ctx, cleanup) — runs on cancel |
for i := 0; i < b.N; i++ in benchmarks | for b.Loop() |
strings.Split in for range | strings.SplitSeq / strings.FieldsSeq (also bytes.*Seq) |
omitempty for Duration/Time/struct/slice/map | omitzero |
reflect.TypeOf((*T)(nil)).Elem() | reflect.TypeFor[T]() |
http.DefaultClient (no timeout) | Inject *http.Client with explicit Timeout via constructor |
http.ServeMux without methods | mux.HandleFunc("GET /api/{id}", h) + r.PathValue("id") |
time.NewTicker when Tick suffices | time.Tick — GC-safe since 1.23 |
npx claudepluginhub klaidliadon/skillsSearches MemPalace before answering questions about past work, people, projects, or prior decisions. Returns verbatim stored content instead of guessing from model memory.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Implements vector databases with Pinecone, Weaviate, Qdrant, Milvus, pgvector for semantic search, RAG, recommendations, and similarity systems. Optimizes embeddings, indexing, and hybrid search.