Filters Nobody Planned For: Binding attr[color]=red Into Go Maps in Fiber v3.7
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.
