add more adpater documenation

improve_docs
René 2025-02-20 13:52:23 +01:00
parent cdb862add1
commit d655e08a48
2 changed files with 7 additions and 9 deletions

View File

@ -178,7 +178,7 @@ If more information is needed, please refer to this issue [#750](https://github.
## How can I handle conversions between Fiber and net/http? ## How can I handle conversions between Fiber and net/http?
The `adaptor` package provides utilities for converting between Fiber and `net/http`. It allows seamless integration of `net/http` handlers, middleware, and requests into Fiber applications, and vice versa. The `adaptor` middleware provides utilities for converting between Fiber and `net/http`. It allows seamless integration of `net/http` handlers, middleware, and requests into Fiber applications, and vice versa.
For details on how to: For details on how to:

View File

@ -6,8 +6,6 @@ id: adaptor
The `adaptor` package provides utilities for converting between Fiber and `net/http`. It allows seamless integration of `net/http` handlers, middleware, and requests into Fiber applications, and vice versa. The `adaptor` package provides utilities for converting between Fiber and `net/http`. It allows seamless integration of `net/http` handlers, middleware, and requests into Fiber applications, and vice versa.
Special thanks to [@arsmn](https://github.com/arsmn) for contributions!
## Features ## Features
- Convert `net/http` handlers and middleware to Fiber handlers. - Convert `net/http` handlers and middleware to Fiber handlers.
@ -23,8 +21,8 @@ Special thanks to [@arsmn](https://github.com/arsmn) for contributions!
| `HTTPMiddleware` | `HTTPMiddleware(mw func(http.Handler) http.Handler) fiber.Handler` | Converts `http.Handler` middleware to `fiber.Handler` middleware | | `HTTPMiddleware` | `HTTPMiddleware(mw func(http.Handler) http.Handler) fiber.Handler` | Converts `http.Handler` middleware to `fiber.Handler` middleware |
| `FiberHandler` | `FiberHandler(h fiber.Handler) http.Handler` | Converts `fiber.Handler` to `http.Handler` | | `FiberHandler` | `FiberHandler(h fiber.Handler) http.Handler` | Converts `fiber.Handler` to `http.Handler` |
| `FiberHandlerFunc` | `FiberHandlerFunc(h fiber.Handler) http.HandlerFunc` | Converts `fiber.Handler` to `http.HandlerFunc` | | `FiberHandlerFunc` | `FiberHandlerFunc(h fiber.Handler) http.HandlerFunc` | Converts `fiber.Handler` to `http.HandlerFunc` |
| `FiberApp` | `FiberApp(app *fiber.App) http.HandlerFunc` | Converts an entire Fiber app to an `http.HandlerFunc` | | `FiberApp` | `FiberApp(app *fiber.App) http.HandlerFunc` | Converts an entire Fiber app to a `http.HandlerFunc` |
| `ConvertRequest` | `ConvertRequest(c fiber.Ctx, forServer bool) (*http.Request, error)` | Converts `fiber.Ctx` into an `http.Request` | | `ConvertRequest` | `ConvertRequest(c fiber.Ctx, forServer bool) (*http.Request, error)` | Converts `fiber.Ctx` into a `http.Request` |
| `CopyContextToFiberContext` | `CopyContextToFiberContext(context any, requestContext *fasthttp.RequestCtx)` | Copies `context.Context` to `fasthttp.RequestCtx` | | `CopyContextToFiberContext` | `CopyContextToFiberContext(context any, requestContext *fasthttp.RequestCtx)` | Copies `context.Context` to `fasthttp.RequestCtx` |
--- ---
@ -48,7 +46,7 @@ import (
func main() { func main() {
app := fiber.New() app := fiber.New()
// Convert an http.Handler to a Fiber handler // Convert a http.Handler to a Fiber handler
app.Get("/", adaptor.HTTPHandler(http.HandlerFunc(helloHandler))) app.Get("/", adaptor.HTTPHandler(http.HandlerFunc(helloHandler)))
app.Listen(":3000") app.Listen(":3000")
@ -59,7 +57,7 @@ func helloHandler(w http.ResponseWriter, r *http.Request) {
} }
``` ```
### 2. Using `net/http` Middleware in Fiber ### 2. Using `net/http` Middleware with Fiber
Middleware written for `net/http` can be used in Fiber: Middleware written for `net/http` can be used in Fiber:
@ -76,7 +74,7 @@ import (
func main() { func main() {
app := fiber.New() app := fiber.New()
// Apply an http middleware in Fiber // Apply a http middleware in Fiber
app.Use(adaptor.HTTPMiddleware(loggingMiddleware)) app.Use(adaptor.HTTPMiddleware(loggingMiddleware))
app.Get("/", func(c fiber.Ctx) error { app.Get("/", func(c fiber.Ctx) error {
@ -148,7 +146,7 @@ func main() {
### 5. Converting Fiber Context (`fiber.Ctx`) to `http.Request` ### 5. Converting Fiber Context (`fiber.Ctx`) to `http.Request`
If you need to use an `http.Request` inside a Fiber handler: If you need to use a `http.Request` inside a Fiber handler:
```go ```go
package main package main