Go Service Rules

    by mochalatte

    1

    Enforce memory-safe concurrency, context propagation, and structured error handling in Go services.

    Secure checkout via Stripe

    0 installsSecurity scanned

    Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLI+17 more

    See it in action

    You say

    Our sync service memory climbs until it gets OOM killed. It fans out to an API, one goroutine per order, results on a channel. If one fails, we return the error. How do I fix the leak?

    Your agent does

    Concurrency map

    One goroutine per order, unbounded. One results channel with no buffer.

    Findings

    sync.go: Goroutine Lifetime rule 3. On error return, in-flight goroutines block forever on the unbuffered channel.

    Patch

    [Full code using errgroup.SetLimit and buffered channels...]

    What you get

    Prevent memory leaks by defining explicit goroutine exit paths.Implement bounded concurrency for API fan-out using errgroup.Harden HTTP servers with proper read/write timeouts and graceful shutdown.Standardize error wrapping and inspection using errors.Is and errors.As.

    About this skill

    The problem

    Go makes concurrency easy to write but difficult to debug at scale. Silent goroutine leaks, unbuffered channel deadlocks, and missing context deadlines often pass unit tests only to crash services under production load.

    What it does

    • Analyzes goroutine lifetimes to ensure every routine has a defined exit path and cancellation listener.
    • Identifies unsafe channel patterns, including receiver-side closes and unbuffered sends that lack select blocks.
    • Audits context propagation to prevent disconnected cancellation chains and missing request deadlines.
    • Refactors error handling to use structured wrapping with errors.Is and errors.As instead of bare returns.
    • Hardens net/http implementations by enforcing timeouts and graceful shutdown sequences.

    Frameworks & tools

    Go 1.22+, errgroup, context, net/http, and the Go race detector.

    Why this beats prompting it yourself

    Generic LLMs often suggest code that compiles but leaks memory. This skill applies a strict "Starter owns the Stopper" ownership model and forces a Concurrency Map for every change, ensuring structural integrity that a standard prompt misses.

    Use cases

    • Fixing OOM kills caused by growing goroutine counts in long-running services.
    • Implementing safe fan-out patterns using limited errgroup concurrency.
    • Adding graceful shutdown to HTTP servers to prevent dropped requests during deployments.
    • Standardizing error wrapping across a microservice to improve observability.

    Known limitations

    This skill reviews and rewrites code in the editor but does not execute go test, the race detector, or profilers. Verification requires manual command execution.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean 1 day ago

    Listed1 day ago

    Frequently Asked Questions

    Popular in AI Agents & LLM Ops