anantbhandarkar/make-it-right/mir-backend-go-fiber

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Make It Right (Fiber module). Fiber web framework reliability augmentation for Go backends, covering Fiber v3 (current) and v2 (still patched). Chains: mir-backend (generic gates) -> mir-backend-go (Go runtime) -> this (Fiber library mechanics). Adds the mechanical footguns the runtime-agnostic tiers omit: fiber.Ctx and every value read from it (Body, Params, Query, Headers) are pooled and reused after the handler returns, so retaining them corrupts or discloses another request's data; the v2->v3 API rewrite that AI mixes up (Ctx is now an interface, BodyParser became c.Bind().Body(), c.Context() returns a context.Context, TrustedProxies became TrustProxyConfig); c.Bind() silently skips validation when fiber.Config.StructValidator is nil; fasthttp's incompatibility with net/http middleware; and graceful shutdown via ListenConfig.GracefulContext or app.ShutdownWithContext, which hangs on keep-alive connections when ReadTimeout is 0. TRIGGER only when the Go backend uses the Fiber framework - building, reviewing, or debugging a Fiber handler, middleware, or route. SKIP for Gin (mir-backend-go-gin), Echo (mir-backend-go-echo), chi, stdlib net/http, or any non-Fiber stack, and for every non-Go runtime.

Install

npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-go-fiber

SKILL.md

The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-go-fiber.

/mir-backend-go-fiber · Make It Right (Fiber)

Bottom tier of the chain: mir-backend (generic gates) → mir-backend-go (Go runtime model) → this (Fiber library mechanics). Run the gates first; load the Go runtime tier for goroutine lifecycle, context propagation, and race discipline; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (goroutine leaks, data races, context propagation, typed-nil, slice aliasing, `os.Root`, module checksums) live in `mir-backend-go` — not here.

Stack state, verified 13 Aug 2026.

LineCurrentNotes
v3 (github.com/gofiber/fiber/v3)v3.4.0 (2026-07-02); v3.0.0 GA 2026-02-02Current major. go.mod requires Go 1.25. fiber migrate --to v3 assists the port
v2 (github.com/gofiber/fiber/v2)v2.52.15 (2026-08-12)Still receiving security patches. Different handler signature and binding API

Establish which major the project is on before writing a line. The two have different handler signatures, a different binding API, and different config field names — code written for one does not compile against the other, and AI mixes them constantly (footgun 2).

Fiber is built on fasthttp, not on net/http. That is the root of most Fiber-specific footguns.

The Fiber footguns AI walks into most

1. fiber.Ctx and every value read from it are pooled — retaining them is data corruption

This is Fiber's defining hazard, and it is unchanged in v3. Fiber reuses the request context from a sync.Pool after the handler returns. Every string and byte slice obtained from `fiber.Ctx` — `c.Body()`, `c.Params("id")`, `c.Get("X-Header")`, `c.Query("page")`, `c.Locals(...)` — points into the reused buffer. When the pool recycles the slot for the next request, those references now read the next request's data.

go
// WRONG: id and body point at pooled buffers; the goroutine reads another request's data
func handler(c fiber.Ctx) error {
id := c.Params("id")
body := c.Body()
go func() { process(id, body) }()
return c.SendStatus(fiber.StatusAccepted)
}
// RIGHT: copy strings, copy body bytes, detach the context — all before returning
func handler(c fiber.Ctx) error {
id := strings.Clone(c.Params("id")) // stdlib; no Fiber import needed
body := bytes.Clone(c.Body())
ctx := context.WithoutCancel(c.Context()) // survives the handler; keeps values, drops cancellation
go func() { process(ctx, id, body) }()
return c.SendStatus(fiber.StatusAccepted)
}
  • Applies to every value read from c: params, query, headers, body, locals. When in doubt, copy.
  • Use `strings.Clone` / `bytes.Clone`, not `utils.CopyString`. The import path differs by major and AI gets it wrong: v2 has github.com/gofiber/fiber/v2/utils, but v3 has no `utils` subpackage — CopyString moved to the separate module github.com/gofiber/utils/v2. The stdlib functions work in both.
  • Binding is not an escape hatch, except for JSON. c.Bind().Body(&req) on a JSON body goes through encoding/json and yields heap-allocated fields you can retain. The form, multipart, query, header, and cookie binders hand the decoder utils.UnsafeString(val) over the fasthttp buffer, so those struct fields still alias the pooled memory. Retaining a struct filled by .Query(), .Form(), .Header(), or .Cookie() has the same corruption as retaining c.Query(...) directly.
  • With Immutable on (footgun 5), use app.GetString(s) / app.GetBytes(b) to get a value that is safe to keep; they return the argument unchanged when Immutable is off, so they are not a substitute for an explicit copy.
  • The race detector will not catch this. The pool recycles the slot after the handler returns, so there is no concurrent access in the Go memory-model sense — it is a logical corruption. Symptom to recognise: a panic or garbled data in a package that never mentions Fiber in the stack trace.
  • This is a confidentiality bug as well as a correctness bug — see Security.
2. v2 and v3 are different APIs — do not mix them

The single most common source of code that does not compile, or that compiles and means something else.

Concernv2v3
Handler signaturefunc(c *fiber.Ctx) error (struct pointer)func(c fiber.Ctx) error (Ctx is an interface)
Standard Go contextc.UserContext()c.Context() / c.SetContext(ctx)
fasthttp contextc.Context()c.RequestCtx()
Body bindingc.BodyParser(&req)c.Bind().Body(&req)
Query / params / cookie bindingc.QueryParser, c.ParamsParser, c.CookieParserc.Bind().Query(), .URI(), .Cookie() (the params struct tag became uri)
Template data bindingc.Bind(...)c.ViewBind(...)
Trusted proxiesEnableTrustedProxyCheck + TrustedProxiesTrustProxy + TrustProxyConfig.Proxies
CORS list optionscomma-separated stringsslices
CSRF expiryExpiration (1 h)IdleTimeout (30 min)

c.Context() flipping meaning between majors is the dangerous one: in v2 it returns *fasthttp.RequestCtx, in v3 it returns a context.Context. Code ported without care compiles in neither, or compiles and passes the wrong thing to a database call.

3. c.Bind() silently skips validation when no StructValidator is configured

Fiber v3 runs your validator inside every Bind call — but only if one exists. fiber.Config.StructValidator defaults to nil, and the binder then returns success without checking a single tag. Structs decorated with validate:"required,email" pass straight through to your business logic.

go
type structValidator struct{ v *validator.Validate }
func (s *structValidator) Validate(out any) error { return s.v.Struct(out) }
app := fiber.New(fiber.Config{
StructValidator: &structValidator{v: validator.New()},
})
  • With that wired, c.Bind().Body(&req) parses and validates in one call. Without it, Bind is a decoder and nothing more.
  • Error handling is manual by default: Bind does not write a response unless you chain .WithAutoHandling() (which sets 400 and returns a *fiber.Error). Always check and return the error.
  • .SkipValidation(true) disables validation for one chain — grep for it during review; it is an easy way to accidentally disable the only input check on an endpoint.
  • v2 has no validator hook at all: BodyParser never validates. Call validator.Struct(&req) yourself after every parse.
  • Never bind into your DB/ORM model in either major — see Security, mass assignment.
4. fasthttp ≠ net/http — standard middleware and libraries may not work

fasthttp provides its own RequestCtx and does not implement http.Handler or http.ResponseWriter. Anything expecting net/http types — standard middleware, net/http-based auth libraries, net/http OpenTelemetry instrumentation, net/http.CrossOriginProtection — cannot be used directly with Fiber.

  • Look for a Fiber-native equivalent in gofiber/contrib or the built-in middleware/ set first.
  • To reuse a net/http handler, wrap it with adaptor.HTTPHandler / adaptor.HTTPMiddleware (v3 middleware/adaptor). This converts types; it does not solve the buffer-pooling problem for values you read via fiber.Ctx.
  • fasthttp does not support HTTP/2. If a client, a gRPC-Web gateway, or a load-balancer health check requires h2, Fiber is the wrong choice — surface it at Gate 0 stack fitness, not after implementation.
  • Always check the ecosystem tier before adding a dependency: does it export a Fiber middleware, a fasthttp handler, or only an http.Handler?
5. Immutable — pick one mode and enforce it project-wide

By default (Immutable: false), strings returned by Fiber reference the fasthttp buffer directly for zero-allocation performance, and become invalid after the handler returns (footgun 1). Immutable: true makes Fiber copy every returned string, so values are safe to retain — at the cost of an allocation per read.

go
app := fiber.New(fiber.Config{Immutable: true})
  • `Immutable: true` — simpler, safer code. The right default for CRUD APIs where correctness is worth the allocations. It covers c.Body() too: both majors route the body through the copying path (app.GetBytes in v3, utils.CopyBytes in v2).
  • `Immutable: false` — every retained string needs strings.Clone, every retained body needs bytes.Clone.
  • Document the choice and enforce it. A codebase where some files assume true and others assume false has latent corruption that only appears under concurrent load.
6. Graceful shutdown — and the ReadTimeout: 0 trap

Ignoring SIGTERM drops in-flight requests. But wiring shutdown without setting ReadTimeout produces a shutdown that appears to hang: `Shutdown` does not close idle keep-alive connections, so with ReadTimeout: 0 those connections never time out and the drain waits for the full deadline on every deploy.

go
app := fiber.New(fiber.Config{
ReadTimeout: 15 * time.Second, // required for Shutdown to complete promptly
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second, // falls back to ReadTimeout when zero
})
// v3: declarative — Listen drains when ctx is canceled
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
if err := app.Listen(":8080", fiber.ListenConfig{
GracefulContext: ctx,
ShutdownTimeout: 30 * time.Second,
}); err != nil {
slog.Error("listen failed", "err", err)
}
  • The manual form works in both majors: run app.Listen in a goroutine, wait on the signal, then app.ShutdownWithContext(ctx) with a bounded deadline. Never app.Shutdown() without a context — it blocks indefinitely if a request does not finish.
  • ReadTimeout, WriteTimeout, and IdleTimeout all default to zero, meaning no limit. Set them explicitly; a slow client otherwise holds a connection forever.
  • Register OnPreShutdown / OnPostShutdown hooks (v3; v2's single OnShutdown was split) to fail readiness probes before the drain starts, then close DB pools after it ends.
  • Goroutines you spawned inside handlers are not tracked by Shutdown. Wait on your own errgroup too.
7. Prefork forks processes — in-memory state is silently partitioned

Prefork (fiber.Config.Prefork in v2, fiber.ListenConfig.EnablePrefork in v3) spawns one child OS process per core, all listening on the same port with SO_REUSEPORT. It is off by default and is a throughput knob people turn on from a blog post.

Every process gets its own copy of every global. Nothing in the process is shared, so anything counted in memory is counted N times:

Built in memoryWhat actually happens with prefork on
limiter middleware with the default memory storeEach child enforces the limit independently. 8 children on a "10 req/min" rule permits 80
session middleware with the default memory storeA user's session exists in one child; the next request lands on another and they are logged out
csrf middleware with the default storageSame — the token is unknown to the child that receives the form post
idempotency middleware, in-process caches, dedupe mapsPer child. Duplicate charges, duplicate sends
A cron/ticker started in mainRuns once per child. N duplicate jobs

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-go-fiber/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-go-fiber)

Something wrong with this skill or its page? Tell us.