Skip to content

v0.5.0

Latest

Choose a tag to compare

@yousuf64 yousuf64 released this 31 Dec 14:36

Breaking Changes

  • Params.ForEach(cb): now the callback doesn't have a return type.
    • Previously, the iteration was interrupted by returning false from 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() or Params.Map() and use the break keyword:
        • Example 1: for _, param := range route.Params.Slice() { ... }.
        • Example 2: for k, v := range route.Params.Map() { ... }.
      • For cases where it always returned true, you can now simply remove the return true.
  • Route.Params is changed from a pointer to a non-pointer.
    • This is to prevent Route.Params from 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.Params stores data in a backing *internalParams object. This design is inspired by the SliceHeader implementation.
    • Even though now it is a non-pointer, it's still precautionary to copy the Params using Params.Copy() before using it in another Goroutine / using it beyond the request lifecycle.

Enhancements & Fixes

  • Used new methods provided in the unsafe package with Go 1.20 for efficient byte-to-string conversion (Go 1.18 and above are still supported through build constraints).
  • Recover middleware no longer responds with the stack trace. Instead, stack track is written to os.Stdout. To write to a different destination, a new RecoverWithWriter middleware is provided.
  • It's no longer needed for the RouteContext middleware to precede the Recover middleware to minimize allocations.
  • Exposed Key and Value fields in the Param struct (returned by Params.Slice()).
  • Fixed issue where calling Params.Slice() and Params.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.