← ClaudeAtlas

go-opslisted

Production Go operations advisor. Always use this skill when deploying or operating Go applications, handling graceful shutdown, signal handling, health checks, structured logging, profiling with pprof, or managing configuration. Use when the user asks 'how do I handle SIGTERM in Go', 'graceful shutdown in Go', 'how do I add health checks', 'how do I profile a Go service', 'structured logging in Go', 'slog vs zerolog vs zap', 'how do I read config from env vars', or 'Go kubernetes'. Read this skill before advising on any Go production or deployment topic.
AllThingsSmitty/agent-skills · ★ 1 · Code & Development · score 74
Install: claude install-skill AllThingsSmitty/agent-skills
## Graceful Shutdown Never use `log.Fatal(http.ListenAndServe(...))`. It makes your service unkillable gracefully — Kubernetes sends SIGTERM and your pods drop in-flight requests. The correct pattern uses `signal.NotifyContext` (Go 1.16+) or `signal.Notify` with a channel: ```go package main import ( "context" "errors" "log/slog" "net/http" "os" "os/signal" "syscall" "time" ) func main() { srv := &http.Server{ Addr: ":8080", Handler: routes(), } // Catch SIGINT and SIGTERM ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() // Start serving in a goroutine go func() { slog.Info("server starting", "addr", srv.Addr) if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { slog.Error("server error", "err", err) os.Exit(1) } }() // Block until signal received <-ctx.Done() slog.Info("shutdown signal received") // Give in-flight requests up to 30 seconds to complete shutdownCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() if err := srv.Shutdown(shutdownCtx); err != nil { slog.Error("shutdown error", "err", err) os.Exit(1) } slog.Info("server stopped cleanly") } ``` Key rules: - Use `Shutdown(ctx)` not `Close()` — `Shutdown` waits for in-flight requests; `Close` drops them. - Al