v2.40.0
❗ BreakingChange
- Bump github.com/valyala/fasthttp from 1.40.0 to 1.41.0 (#2171)
- Deprecate: go 1.14 & go 1.15 support deprecation (#2172)
Due to the fact that fasthttp, which fiber is based on in release 1.41.0, does not support go versions 1.14 & 1.15 anymore, we had to remove them from our package as well.
🚀 New
- Register custom methods (#2107)
https://docs.gofiber.io/api/fiber#config
// now you can add your own custom methods
app := fiber.New(fiber.Config{
RequestMethods: append(fiber.DefaultMethods, "LOAD", "TEST"),
})
app.Add("LOAD", "/hello", func(c *fiber.Ctx) error {
return c.SendString("Hello, World 👋!")
})
- Add multiple-prefix support to app.Use() and group.Use() (#2205)
https://docs.gofiber.io/api/app#route-handlers - More like Express
// declaration of multiple paths for the ".Use" method as in express is now possible
app.Use([]string{"/john", "/doe"}, func(c *Ctx) error {
return c.SendString(c.Path())
})
- Allow optional params with route constraints (#2179)
https://docs.gofiber.io/guide/routing#constraints
app.Get("/:userId<int>?", func(c *fiber.Ctx) error {
return c.SendString(c.Params("userId"))
})
// curl -X GET http://localhost:3000/42
// 42
// curl -X GET http://localhost:3000/
//
- Improve mounting behavior (#2120)
https://docs.gofiber.io/api/app#mount https://docs.gofiber.io/api/app#mountpath
app := fiber.New()
micro := fiber.New()
// order when registering the mounted apps no longer plays a role
app.Mount("/john", micro)
// before there was problem when after mounting routes were registered
micro.Get("/doe", func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})
// output of the mount path possible
micro.MountPath() // "/john"
- Middleware/pprof: Add URL prefix to pprof middleware (#2194)
https://docs.gofiber.io/api/middleware/pprof
// In systems where you have multiple ingress endpoints, it is common to add a URL prefix, like so:
app.Use(pprof.New(pprof.Config{Prefix: "/endpoint-prefix"}))
- Middleware/logger: Add customTags in Config (#2188, #2224, #2225)
https://docs.gofiber.io/api/middleware/logger#add-custom-tags
app.Use(logger.New(logger.Config{
Format: "[${time}] ${status} - ${latency} ${method} ${randomNumber} ${path}\n",
CustomTags: map[string]logger.LogFunc{
// possibility to adapt or overwrite existing tags
logger.TagMethod: func(output logger.Buffer, c *fiber.Ctx, data *logger.Data, extraParam string) (int, error) {
return output.WriteString(utils.ToLower(c.Method()))
},
// own tags can be registered
"randomNumber": func(output logger.Buffer, c *fiber.Ctx, data *logger.Data, extraParam string) (int, error) {
return output.WriteString(strconv.FormatInt(rand.Int63n(100), 10))
},
},
}))
// [17:15:17] 200 - 0s get 10 /test
// [17:15:17] 200 - 0s get 51 /test
- Middleware/logger: Add callback function (#2219)
https://docs.gofiber.io/api/middleware/logger#callback-after-log-is-written
app.Use(logger.New(logger.Config{
// is triggered when the handlers has been processed
Done: func(c *fiber.Ctx, logString []byte) {
// allows saving the logging string to other sources
if c.Response().StatusCode() != fiber.StatusOK {
reporter.SendToSlack(logString)
}
},
}))
🧹 Updates
- Track Configured Values (#2221)
- Ctx: simplify Protocol() (#2217)
- Ctx: make Secure() also report whether a secure connection was established to a trusted proxy (#2215)
- Ctx: update Locals function to accept interface{} key (#2144)
- Utils: reduce diff to external utils package (#2206)
- Utils: Update HTTP status codes (#2203)
- Utils: Replace UnsafeBytes util with suggested way (#2204)
- Fix and optimize memory storage (#2207)
- Leverage runtime/debug to print the full stack trace info (#2183)
- Ci: add check-latest param in vulncheck.yml (#2197)
- Ci: replace snyk with govulncheck (#2178)
🐛 Fixes
- Fix naming of routes inside groups (#2199)
📚 Documentation
- Update list of third-party library licenses (#2211)
- Update README_zh-CN.md (#2186)
- Add korean translate in Installation section (#2213)
- Comment typo (#2173)
- Cache readme and docs update (#2169)
Full Changelog: v2.39.0...v2.40.0
Thank you @Skyenought, @calebcase, @efectn, @gandaldf, @gmlewis, @jamestiotio, @leonklingele, @li-jin-gou, @marcmartin13, @panjf2000, @pjebs, @rafimuhammad01 and @thor-son for making this update possible.