Repository navigation
Breaking Changes
Params.ForEach(cb): now the callback doesn't have a return type.- Previously, the iteration was interrupted by returning
falsefrom the callback. While this could be useful, it is unidiomatic and introduces additional boilerplate. - To address this, the return type has been removed from the callback signature for simplicity.
- Migration:
- For cases requiring interruption or short-circuiting, it is recommended to iterate over
Params.Slice()orParams.Map()and use thebreakkeyword:- Example 1:
for _, param := range route.Params.Slice() { ... }. - Example 2:
for k, v := range route.Params.Map() { ... }.
- Example 1:
- For cases where it always returned
true, you can now simply remove thereturn true.
- For cases requiring interruption or short-circuiting, it is recommended to iterate over
- Previously, the iteration was interrupted by returning
Route.Paramsis changed from a pointer to a non-pointer.- This is to prevent
Route.Paramsfrom being modified through pointer dereference:- Previously, bad Params could sneak into the Params pool, resulting in corrupt behavior.
- Also, emptyParams could be replaced, which could creep into all the static request handlers.
- With this change,
Route.Paramsstores data in a backing*internalParamsobject. This design is inspired by theSliceHeaderimplementation. - Even though now it is a non-pointer, it's still precautionary to copy the
ParamsusingParams.Copy()before using it in another Goroutine / using it beyond the request lifecycle.
- This is to prevent
Enhancements & Fixes
- Used new methods provided in the
unsafepackage with Go 1.20 for efficient byte-to-string conversion (Go 1.18 and above are still supported through build constraints). Recovermiddleware no longer responds with the stack trace. Instead, stack track is written toos.Stdout. To write to a different destination, a newRecoverWithWritermiddleware is provided.- It's no longer needed for the
RouteContextmiddleware to precede theRecovermiddleware to minimize allocations. - Exposed
KeyandValuefields in theParamstruct (returned byParams.Slice()). - Fixed issue where calling
Params.Slice()andParams.Map()from a static route causes a panic. - Fixed issue #9.
Full changelog: v0.4.0...v0.5.0
In addition, there will likely be other breaking/behavior changes before the 1.0.0 release as we standardize the API.