/major-ai-skills:go-servicesfrom major-ai-skills
Build production Go HTTP services with Go 1.22+ ServeMux patterns, context cancellation, graceful Shutdown deadlines, middleware, race-safe tests, and multi-stage Docker binaries.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Go services ship as single static binaries: net/http (or a thin http.Handler router) accepts traffic, goroutines handle concurrency, and context.Context carries deadlines and cancellation into DB/HTTP clients. Since Go 1.22, stdlib ServeMux supports method + wildcard patterns (GET /items/{id}). Agents treat timeouts, context propagation, and deadline-bounded Shutdown as first-class contracts—not optional polish.
┌─────────────────────────────────────────────────────────────┐
│ Go HTTP service path │
│ │
│ main / cmd/<svc> │
│ ├── signal.NotifyContext → cancel root ctx │
│ └── http.Server{ timeouts + Handler } │
│ │
│ Handler stack │
│ ├── middleware: recover / request-id / access log │
│ ├── ServeMux: "METHOD /path/{id}" → handlers │
│ └── handlers → services → stores (ctx first arg) │
│ │
│ Lifecycle │
│ ├── readiness flip → srv.Shutdown(fresh deadline ctx) │
│ └── close pools / workers (reverse init order) │
└─────────────────────────────────────────────────────────────┘
Use when
cmd/ + internal/ modules, middleware, and table-driven go test.Do not use when
@graphql-apis (Go host still OK for transport).@nodejs / @express / @nextjs.0.0.0.0 admin debug without auth, or disable TLS verification in prod → refuse; use env/secret stores and @docker/@vault patterns.ctx context.Context as the first parameter; pass r.Context() (or a child with timeout) into stores and outbound clients.ReadHeaderTimeout; usually also ReadTimeout, WriteTimeout, IdleTimeout. Zero-value http.Server never times out (Slowloris risk).GET /items/{id}, r.PathValue("id")) unless the team already standardized on chi/echo/gin.%w; map to stable HTTP status at the edge; do not panic for control flow.context.WithTimeout(context.Background(), …) for srv.Shutdown—never the already-canceled signal ctx (instant abort).http.Client (with Timeout) per outbound dependency; never http.Get / new client per request (pool thrash).go test ./..., go test -race on concurrent packages, go vet; put binaries under cmd/<name>.package main
import (
"context"
"encoding/json"
"errors"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
type ItemIn struct {
SKU string `json:"sku"`
Qty int `json:"qty"`
}
func createItem(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, 1<<20)
var in ItemIn
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
http.Error(w, "bad json", http.StatusBadRequest)
return
}
if in.SKU == "" || in.Qty < 0 {
http.Error(w, "invalid item", http.StatusBadRequest)
return
}
// pass r.Context() into stores; honor cancel on client disconnect
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusCreated)
_ = json.NewEncoder(w).Encode(map[string]any{"sku": in.SKU, "qty": in.Qty})
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
})
mux.HandleFunc("POST /items", createItem)
srv := &http.Server{
Addr: ":8080",
Handler: mux,
ReadHeaderTimeout: 5 * time.Second,
ReadTimeout: 15 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
}
root, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
errCh := make(chan error, 1)
go func() {
slog.Info("listening", "addr", srv.Addr)
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
errCh <- err
}
close(errCh)
}()
select {
case <-root.Done():
slog.Info("shutdown signal")
case err := <-errCh:
if err != nil {
slog.Error("server crashed", "err", err)
os.Exit(1)
}
}
// Fresh deadline — do NOT pass canceled root ctx into Shutdown
shutdownCtx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
defer cancel()
if err := srv.Shutdown(shutdownCtx); err != nil {
slog.Error("drain failed", "err", err)
_ = srv.Close()
os.Exit(1)
}
}
Layout + validation:
go mod init example.com/inventory
# cmd/inventory-api/main.go internal/…
go test ./...
go test -race ./...
go vet ./...
go build -trimpath -ldflags="-s -w" -o bin/inventory-api ./cmd/inventory-api
Multi-stage image: pair with @docker (builder → scratch/distroless non-root). Datastore migrations: golang-migrate / goose beside @postgresql.
| Signature | Likely cause | Fix path |
|---|---|---|
| 502s / dropped in-flight on deploy | Shutdown got canceled signal ctx → instant return | Fresh WithTimeout(context.Background(), …) for drain |
| Handlers keep running after client leave | Ignored r.Context() / no select on ctx.Done() | Propagate ctx into DB/HTTP; cancel long work |
| Slowloris / hung conns | Missing ReadHeaderTimeout (and friends) | Set server timeouts; per-route TimeoutHandler if needed |
panic: … patterns … conflict at start | Ambiguous ServeMux overlaps | Make one pattern more specific; fix registration |
| Connection pool exhaustion outbound | New http.Client/Transport per request | One client; raise MaxIdleConnsPerHost if fan-out |
| Flaky tests / data races | Shared maps, global mutable clients | Inject deps; go test -race |
| Binary huge / glibc mismatch in container | cgo or fat base | CGO_ENABLED=0; multi-stage @docker |
| Worker never exits on SIGTERM | for { … } without ctx | select on ctx.Done() in loops |
cmd/<name>; libraries in internal/ (or versioned pkg/ only when truly public).slog) with request ID from middleware; never log secrets or full auth headers.MaxBytesReader); validate JSON before side effects.Exec in main.Shutdown does not drain Hijacked connections (WebSockets)—coordinate via RegisterOnShutdown.@docker — multi-stage Go builds, non-root runtime, Compose readiness@postgresql — typical datastore and connection hygiene@graphql-apis — GraphQL schema/resolvers when the API is GraphQL@nodejs / @express — alternative HTTP stacks when the org standard is Node@typescript — typed clients calling this serviceMANDATORY: Propagate
context.Contextinto all I/O. Configurehttp.Servertimeouts. On SIGTERM, drain with a fresh deadline context—never the canceled signal context. Prefer Go 1.22+ ServeMux patterns; rungo test/-racebefore declaring success. Never invent credentials or commit secrets.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job