Skip to main content

40 posts tagged with "go"

View All Tags

Your Symlinks Return 404 on v3.7.0: Root Confinement in the Static Middleware

ยท 20 min read
Fiber Team
Maintainers

A shop runs on a single VM. Every deploy unpacks the build into a new directory under /srv/shop/releases, flips the current link to it, and reloads the service. Product photos and avatars live in /srv/shop/shared/uploads so they survive releases, and the deploy script links that directory into each release as public/uploads. The Fiber app serves /srv/shop/current/public with the static middleware and has done so without trouble for a year.

Then the app moves to Fiber v3.7.0. The tests pass, the deploy goes out, and every avatar on the site turns into a broken image. The CSS still loads, the home page still loads, and the logs show nothing but a stream of 404s for /uploads/.... A few minutes later someone notices that the Apple touch icon and the web fonts are gone too.

The app's code did not change. Fiber v3.7.0 ships fasthttp v1.78.0, and since fasthttp v1.77.0 the file server behind the static middleware resolves every path with Go's os.Root. A file root on disk is now confined: a symbolic link that leads out of it is treated like a missing file. The same release added an opt-out, AllowSymlinksOutsideRoot (#4803). The static documentation states the rule in one paragraph; this post is about what it does to a real deployment. It shows exactly which links are refused, a startup check that lists them before users find them, how to fix each kind without the opt-out, and the paths that the new rule does not cover at all. Everything was built and tested against Fiber v3.7.0 with Go 1.26.11. The option needs Fiber v3.7.0 or later, which needs Go 1.26.

Filters Nobody Planned For: Binding attr[color]=red Into Go Maps in Fiber v3.7

ยท 23 min read
Fiber Team
Maintainers

A shop sells jackets. The product list has filters for color and size, and the handler binds them into a struct with a Color field and a Size field. Then the merchandising team adds "material" to the product data, and a week later "hood" and "waterproof rating". Every new attribute is a new struct field, a new WHERE clause, a code review and a deploy, for something that is really just another row in the attributes table. The frontend team would rather send whatever the data has: ?attr[color]=red&attr[material]=down.

Plenty of APIs already speak this shape. PHP turns it into nested arrays and Rails into nested hashes, Stripe takes metadata[...] this way, JSON:API sets aside the filter parameter family for it, and Express parsed it into objects by default until version 5 switched its default query parser to a simpler one. In Fiber, a struct field of type map[string]string used to be skipped by the binder without a word. A request for exactly this has been open since 2023, and Fiber v3.7.0 closes it: map fields of a struct now bind from query strings and form bodies. This post builds a facet filter on top of it, backed by SQLite, and spends most of its time on what a map hands you: keys chosen by whoever sends the request. Everything was built and tested against Fiber v3.7.0 with modernc.org/sqlite v1.62.0. Map fields need Fiber v3.7.0 or later, which needs Go 1.26 like every release since v3.6.0.

Live HTML Over SSE: Pushing Rendered Fragments With app.Render in Fiber v3.6

ยท 29 min read
Fiber Team
Maintainers

A support team works from a shared queue page. Every agent has it open all day, and the page polls the server every five seconds. Two things go wrong with that. The queue is never quite current, so two agents regularly click "Claim" on the same ticket within the same five seconds, and one of them finds out a few seconds later that their work was wasted. And the polling is mostly empty: thirty open tabs ask the server 360 times a minute whether anything happened, and the answer is nearly always no.

Server-Sent Events fix both. The server keeps one response open per tab and writes to it when something changes. The question is what to write. Sending JSON means a second rendering layer in the browser that has to produce the same markup as your Go templates. Sending HTML means you render the fragment on the server with the same template that renders the full page, and the browser only has to put it in the right place. With htmx and its SSE extension, that last part needs no JavaScript of your own.

Rendering a template used to be tied to a request in Fiber: c.Render writes into the response of the request at hand. An update that one agent triggers has to reach thirty other streams, and none of them is the request that caused it. Fiber v3.6.0 added app.Render, which writes a template through the configured view engine into any io.Writer, with no request involved. This post builds the live queue around it: render each update once, number it, fan it out to every subscriber, replay what a reconnecting browser missed and send a full reset when replay is impossible. Everything was built and tested against Fiber v3.6.1 with html/v3.1.0 of the template engine, htmx 2.0.11 and htmx-ext-sse 2.2.4. app.Render needs Fiber v3.6.0 or later, which requires Go 1.26. The SSE middleware has been there since v3.3.0.