From b95c86237d336dd9a99942d0132765125596c76c Mon Sep 17 00:00:00 2001 From: Fenny <25108519+Fenny@users.noreply.github.com> Date: Thu, 25 Jun 2020 15:54:08 +0200 Subject: [PATCH] Update middleware examples --- .github/README.md | 90 +++++++++++++++++++++------------------- .github/README_ar_SA.md | 91 ++++++++++++++++++++++------------------- .github/README_de.md | 90 +++++++++++++++++++++------------------- .github/README_es.md | 90 +++++++++++++++++++++------------------- .github/README_fr.md | 90 +++++++++++++++++++++------------------- .github/README_he.md | 90 +++++++++++++++++++++------------------- .github/README_id.md | 90 +++++++++++++++++++++------------------- .github/README_ja.md | 90 +++++++++++++++++++++------------------- .github/README_ko.md | 90 +++++++++++++++++++++------------------- .github/README_nl.md | 90 +++++++++++++++++++++------------------- .github/README_pt.md | 90 +++++++++++++++++++++------------------- .github/README_ru.md | 90 +++++++++++++++++++++------------------- .github/README_tr.md | 63 ++++++++++++++-------------- .github/README_zh-CN.md | 90 +++++++++++++++++++++------------------- 14 files changed, 643 insertions(+), 591 deletions(-) diff --git a/.github/README.md b/.github/README.md index 702fdc5d..ddc0263f 100644 --- a/.github/README.md +++ b/.github/README.md @@ -305,29 +305,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -449,54 +454,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_ar_SA.md b/.github/README_ar_SA.md index 09bbd966..3645dee7 100644 --- a/.github/README_ar_SA.md +++ b/.github/README_ar_SA.md @@ -341,29 +341,35 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md)
```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } ``` @@ -510,58 +516,57 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md)
```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -
-## 🧬 الرسمية Middlewares +## 🧬 Fiber Middleware -والمزيد _قابلة للصيانة_ middleware _ecosystem_, لقد وضعنا رسمية [middlewares](https://docs.gofiber.io/middleware) في مستودعات منفصلة: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) + +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_de.md b/.github/README_de.md index 605d5dd7..8ee14473 100644 --- a/.github/README_de.md +++ b/.github/README_de.md @@ -301,29 +301,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -445,54 +450,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_es.md b/.github/README_es.md index 8423d5f6..1564d46c 100644 --- a/.github/README_es.md +++ b/.github/README_es.md @@ -301,29 +301,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -445,54 +450,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_fr.md b/.github/README_fr.md index f266e659..915e0d7c 100644 --- a/.github/README_fr.md +++ b/.github/README_fr.md @@ -301,29 +301,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -445,54 +450,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_he.md b/.github/README_he.md index c4c9fbb7..02adc33f 100644 --- a/.github/README_he.md +++ b/.github/README_he.md @@ -381,31 +381,36 @@ func main() { ### Middleware של לוגים -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md)
```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -```
### שיתוף משאבים בין מקורות (CORS) @@ -543,29 +548,24 @@ func main() { ### Middleware של התאוששות -📖 [התאוששות](https://docs.gofiber.io/middleware#recover) +📖 [התאוששות](https://github.com/gofiber/fiber/blob/master/middleware/recover.md)
```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } @@ -576,33 +576,37 @@ func main() {
-## 🧬 Official Middlewares +## 🧬 Fiber Middleware
-For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people).
-- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - |
diff --git a/.github/README_id.md b/.github/README_id.md index 0b3322a7..284677b4 100644 --- a/.github/README_id.md +++ b/.github/README_id.md @@ -303,29 +303,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -447,54 +452,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_ja.md b/.github/README_ja.md index cb570148..478022e9 100644 --- a/.github/README_ja.md +++ b/.github/README_ja.md @@ -304,29 +304,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -448,54 +453,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_ko.md b/.github/README_ko.md index cb862f06..c4f607e0 100644 --- a/.github/README_ko.md +++ b/.github/README_ko.md @@ -306,29 +306,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -450,54 +455,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_nl.md b/.github/README_nl.md index 8f3768f8..113d30b1 100644 --- a/.github/README_nl.md +++ b/.github/README_nl.md @@ -305,29 +305,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -449,54 +454,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_pt.md b/.github/README_pt.md index 51fada1d..b3975aae 100644 --- a/.github/README_pt.md +++ b/.github/README_pt.md @@ -301,29 +301,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -445,54 +450,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_ru.md b/.github/README_ru.md index 9ce5d96b..c192c69e 100644 --- a/.github/README_ru.md +++ b/.github/README_ru.md @@ -303,29 +303,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -447,54 +452,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Официальные Middlewares +## 🧬 Fiber Middleware -Чтобы создать более _поддерживаемую_ middleware _экосистему_, мы вынесли [middlewares](https://docs.gofiber.io/middleware) в отдельные репозитории: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Middlewares от сторонних разработчиков diff --git a/.github/README_tr.md b/.github/README_tr.md index 45026a9e..1a77e172 100644 --- a/.github/README_tr.md +++ b/.github/README_tr.md @@ -301,7 +301,7 @@ func main() { ### Ara Katman Günlükcüsü(Logger) -📖 [Günlükcü](https://docs.gofiber.io/middleware#logger) +📖 [Günlükcü](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( @@ -443,56 +443,55 @@ func main() { } ``` -### Ara Katman'dan Kurtarma +### Recover middleware -📖 [Kurtar](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Özelleştirilebilir kurtarma ayarı - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Özelleştrilebilir günlükleme - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares diff --git a/.github/README_zh-CN.md b/.github/README_zh-CN.md index 42eb3180..3ed70e17 100644 --- a/.github/README_zh-CN.md +++ b/.github/README_zh-CN.md @@ -304,29 +304,34 @@ func main() { ### Middleware logger -📖 [Logger](https://docs.gofiber.io/middleware#logger) +📖 [Logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) ```go import ( - "github.com/gofiber/fiber" - "github.com/gofiber/logger" + "github.com/gofiber/fiber" + "github.com/gofiber/fiber/middleware" ) func main() { - app := fiber.New() + app := fiber.New() - // Optional logger config - config := logger.Config{ - Format: "${time} - ${method} ${path}\n", - TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST", - } + // Default + app.Use(middleware.Logger()) - // Logger with config - app.Use(logger.New(config)) + // Custom logging format + app.Use(middleware.Logger("${method} - ${path}")) - app.Listen(3000) + // Custom Config + app.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + Next: func(ctx *fiber.Ctx) bool { + return ctx.Path() != "/private" + }, + Format: "${method} - ${path}", + Output: io.Writer, + })) + + app.Listen(3000) } -``` ### Cross-Origin Resource Sharing (CORS) @@ -448,54 +453,53 @@ func main() { ### Recover middleware -📖 [Recover](https://docs.gofiber.io/middleware#recover) +📖 [Recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) ```go import ( "github.com/gofiber/fiber" - "github.com/gofiber/recover" + "github.com/gofiber/fiber/middleware" ) func main() { app := fiber.New() - // Optional recover config - config := recover.Config{ - Handler: func(c *fiber.Ctx, err error) { - c.SendString(err.Error()) - c.SendStatus(500) - }, - } + app.Use(middleware.Recover()) - // Logger with custom config - app.Use(recover.New(config)) + app.Get("/", func(c *fiber.Ctx) { + panic("normally this would crash your app") + }) app.Listen(3000) } ``` -## 🧬 Official Middlewares +## 🧬 Fiber Middleware -For an more _maintainable_ middleware _ecosystem_, we've put official [middlewares](https://docs.gofiber.io/middleware) into separate repositories: +The Fiber middleware modules listed here are maintained by the [Fiber team](https://github.com/orgs/gofiber/people). -- [gofiber/compression](https://github.com/gofiber/compression) -- [gofiber/basicauth](https://github.com/gofiber/basicauth) -- [gofiber/requestid](https://github.com/gofiber/requestid) -- [gofiber/websocket](https://github.com/gofiber/websocket) -- [gofiber/keyauth](https://github.com/gofiber/keyauth) -- [gofiber/rewrite](https://github.com/gofiber/rewrite) -- [gofiber/recover](https://github.com/gofiber/recover) -- [gofiber/limiter](https://github.com/gofiber/limiter) -- [gofiber/session](https://github.com/gofiber/session) -- [gofiber/adaptor](https://github.com/gofiber/adaptor) -- [gofiber/logger](https://github.com/gofiber/logger) -- [gofiber/helmet](https://github.com/gofiber/helmet) -- [gofiber/embed](https://github.com/gofiber/embed) -- [gofiber/pprof](https://github.com/gofiber/pprof) -- [gofiber/cors](https://github.com/gofiber/cors) -- [gofiber/csrf](https://github.com/gofiber/csrf) -- [gofiber/jwt](https://github.com/gofiber/jwt) +| Middleware | Description | Built-in middleware | +| :--- | :--- | :--- | +| [adaptor](https://github.com/gofiber/adaptor) | Converter for net/http handlers to/from Fiber request handlers, special thanks to @arsmn! | - | +| [basicauth](https://github.com/gofiber/basicauth) | Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials. | - | +| [compression](https://github.com/Fenny/fiber/blob/master/middleware/compress.md) | Compression middleware for Fiber, it supports `deflate`, `gzip` and `brotli` by default. | `middleware.Compress()` | +| [cors](https://github.com/gofiber/cors) | Enable cross-origin resource sharing \(CORS\) with various options. | - | +| [csrf](https://github.com/gofiber/csrf) | Protect from CSRF exploits. | - | +| [embed](https://github.com/gofiber/embed) | FileServer middleware for Fiber, special thanks and credits to Alireza Salary | - | +| [favicon](https://github.com/gofiber/fiber/blob/master/middleware/favicon.md) | Ignore favicon from logs or serve from memory if a file path is provided. | `middleware.Favicon()` | +| [helmet](https://github.com/gofiber/helmet) | Helps secure your apps by setting various HTTP headers. | - | +| [jwt](https://github.com/gofiber/jwt) | JWT returns a JSON Web Token \(JWT\) auth middleware. | - | +| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware provides a key based authentication. | - | +| [limiter](https://github.com/gofiber/limiter) | Rate-limiting middleware for Fiber. Use to limit repeated requests to public APIs and/or endpoints such as password reset. | - | +| [logger](https://github.com/gofiber/fiber/blob/master/middleware/logger.md) | HTTP request/response logger. | `middleware.Logger()` | +| [pprof](https://github.com/gofiber/pprof) | Special thanks to Matthew Lee \(@mthli\) | - | +| [recover](https://github.com/gofiber/fiber/blob/master/middleware/recover.md) | Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized[ ErrorHandler](error-handling.md). | `middleware.Recover()` | +| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware rewrites the URL path based on provided rules. It can be helpful for backward compatibility or just creating cleaner and more descriptive links. | - | +| [requestid](https://github.com/Fenny/fiber/blob/master/middleware/request_id.md) | Request ID middleware generates a unique id for a request. | `middleware.RequestID()` | +| [session](https://github.com/gofiber/session) | This session middleware is build on top of fasthttp/session by @savsgio MIT. Special thanks to @thomasvvugt for helping with this middleware. | - | +| [template](https://github.com/gofiber/template) | This package contains 8 template engines that can be used with Fiber `v1.10.x` Go version 1.13 or higher is required. | - | +| [websocket](https://github.com/gofiber/websocket) | Based on Fasthttp WebSocket for Fiber with Locals support! | - | ## 🌱 Third Party Middlewares