Releases: loadept/pirca
Release list
v1.3.0
v1.3.0 — Constrain keys store to string type
Summary
Changed the internal keys store from map[any]any to map[string]any, updating Set, Get and Delete to accept string keys instead of any.
Why
- Gin alignment — Gin uses
map[string]anywithSet(string, any). Pirca is explicitly Gin-based, so matching this convention reduces cognitive overhead for users coming from Gin. - No real use case for
anykeys — In practice, every key in a request-scoped store is a string (user ID, role, claims, request ID, etc.). Non-string keys have no realistic application here. - Collision safety via namespacing — The
anykey type is useful incontext.Contextwhere typed keys prevent collisions across packages. But in a local request store, string keys with namespacing ("myapp.user","mymod.role") achieve the same safely with less complexity. - Simplicity — Removing the
anyparameter type makes the API more self-documenting and eliminates an unnecessary abstraction.
Breaking Changes
Set(key any, value any)→Set(key string, value any)Get(key any)→Get(key string)Delete(key any)→Delete(key string)
Migration is mechanical: pass a string as the key argument.
What we expect
This change should be transparent to almost all users since non-string keys were never a documented pattern. The API is now more idiomatic, easier to reason about, and consistent with Gin.
v1.2.0
v1.2.0
Features
- GetBodyWith — new method that caches the raw request body on first read and returns it on subsequent calls without re-reading. Ideal for middlewares that need the raw body (HMAC verification, custom parsing, logging) while allowing downstream handlers to bind the cached body with BindJSONWith, BindXMLWith, etc.
Fixes
- BindBodyWith — added nil body check, returns
pirca: invalid requesterror whenRequest.Bodyis nil instead of panicking
Breaking Changes
None. Fully backward compatible.
v1.1.0
v1.0.1
v1.0.1
Bug fix: ctx.Request apuntaba al *Request incorrecto
ctx.Request se asignaba antes de r.WithContext(ctx), por lo que quedaba apuntando al *Request original en lugar del nuevo *Request que recibe el handler.
WithContext crea una shallow copy del request con un contexto distinto. Aunque los campos compartidos (URL, Header, Body, PathValue, etc.) funcionaban correctamente por ser la misma copia, la comparación ctx.Request == r devolvía false, lo que podía causar bugs en código que:
- Comparara referencias de
*Request - Almacenara
ctx.Requestesperando que fuera idéntico alrdel handler - Inspeccionara la identidad del request entre middlewares
Cambio: ctx.Request ahora se asigna después de r.WithContext(ctx), usando el nuevo *Request que el handler recibe.
v1.0.0
Pirca v1.0.0
Middleware HTTP liviano para Go basado en Gin, con cero dependencias externas.
Características
- Context enriquecido con binders JSON/XML, response writers, cookies, query params, forms, files
- Cero dependencias — solo la stdlib de Go
- Basado en Gin — misma lógica y patrones, sin framework
- Implementa context.Context — pásalo directamente a bases de datos, HTTP clients, etc.
- Captura status code y bytes escritos — ideal para logging y métricas
- Key-value store — comparte datos entre middlewares y handlers
- Control total — ctx.Request y ctx.Writer son los objetos originales de net/http
API
- Body:
Bind,BindJSON,BindJSONStrict,BindXML,BindBodyWith,BindJSONWith,BindJSONStrictWith,BindXMLWith,GetBodyBytes - Response:
JSON,XML,String,Data,Redirect,File,FileFromFS,FileAttachment - Query:
Query,DefaultQuery,GetQuery,QueryArray,GetQueryArray - Path:
Param - Forms:
FormValue,DefaultFormValue,GetFormValue - Files:
FormFile,MultipartForm,SaveUploadedFile - Cookies:
SetCookie,SetCookieData,Cookie,SetSameSite - Headers:
Header,GetHeader - Status:
Status,GetStatus,BytesWritten - Store:
Set,Get,Delete - Context:
Deadline,Done,Err,Value
Ver documentación completa en README.md