mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 20:13:22 +00:00
Update examples
This commit is contained in:
parent
67fc45abd8
commit
49c295313c
@ -14,11 +14,17 @@ import (
|
||||
|
||||
After you initiate your Fiber app, you can use the following possibilities:
|
||||
```go
|
||||
// Default ignore favicon
|
||||
app.Use(middleware.Favicon())
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// Default ignore favicon
|
||||
app.Use(middleware.Favicon())
|
||||
|
||||
// Pass a favicon file that will be cached in memory
|
||||
app.Use(middleware.Favicon("./favicon.ico"))
|
||||
// Pass a favicon file that will be cached in memory
|
||||
app.Use(middleware.Favicon("./favicon.ico"))
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Signatures
|
||||
|
@ -12,30 +12,36 @@ import (
|
||||
|
||||
After you initiate your Fiber app, you can use the following possibilities:
|
||||
```go
|
||||
// Default Logger
|
||||
app.Use(middleware.Logger())
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// Default Logger
|
||||
app.Use(middleware.Logger())
|
||||
|
||||
// Pass a custom output
|
||||
app.Use(middleware.Logger(os.Stdout))
|
||||
// Pass a custom output
|
||||
app.Use(middleware.Logger(os.Stdout))
|
||||
|
||||
// Pass a custom timeformat
|
||||
app.Use(middleware.Logger("15:04:05"))
|
||||
// Pass a custom timeformat
|
||||
app.Use(middleware.Logger("15:04:05"))
|
||||
|
||||
// Pass a custom format
|
||||
app.Use(middleware.Logger("${time} ${method} ${path}"))
|
||||
// Pass a custom format
|
||||
app.Use(middleware.Logger("${time} ${method} ${path}"))
|
||||
|
||||
// Pass a custom timeformat + output + format
|
||||
app.Use(middleware.Logger(os.Stdout, "15:04:05", "${time} ${method} ${path}"))
|
||||
// Pass a custom timeformat + output + format
|
||||
app.Use(middleware.Logger(os.Stdout, "15:04:05", "${time} ${method} ${path}"))
|
||||
|
||||
// Order does not matter
|
||||
app.Use(middleware.Logger("${time} ${method} ${path}", os.Stdout, "15:04:05"))
|
||||
// Order does not matter
|
||||
app.Use(middleware.Logger("${time} ${method} ${path}", os.Stdout, "15:04:05"))
|
||||
|
||||
// Pass a custom config
|
||||
app.Use(middleware.Logger(middleware.LoggerConfig{
|
||||
Format: "${method} ${path}",
|
||||
TimeFormat: "15:04:05",
|
||||
Output: os.Stdout,
|
||||
}))
|
||||
// Pass a custom config
|
||||
app.Use(middleware.Logger(middleware.LoggerConfig{
|
||||
Format: "${method} ${path}",
|
||||
TimeFormat: "15:04:05",
|
||||
Output: os.Stdout,
|
||||
}))
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Signatures
|
||||
|
@ -12,8 +12,14 @@ import (
|
||||
|
||||
After you initiate your Fiber app, you can use the following possibilities:
|
||||
```go
|
||||
// Default recover
|
||||
app.Use(middleware.Recover())
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// Default recover
|
||||
app.Use(middleware.Recover())
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Signatures
|
||||
|
@ -12,27 +12,33 @@ import (
|
||||
|
||||
After you initiate your Fiber app, you can use the following possibilities:
|
||||
```go
|
||||
// Default RequestID
|
||||
app.Use(middleware.RequestID())
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
// Default RequestID
|
||||
app.Use(middleware.RequestID())
|
||||
|
||||
// Custom Header
|
||||
app.Use(middleware.RequestID("X-Custom-Header"))
|
||||
// Custom Header
|
||||
app.Use(middleware.RequestID("X-Custom-Header"))
|
||||
|
||||
// Custom ID generator
|
||||
app.Use(middleware.RequestID(func() string {
|
||||
return "1234567890"
|
||||
}))
|
||||
|
||||
// Custom Config
|
||||
app.Use(middleware.RequestID(middleware.RequestIDConfig{
|
||||
Next: func(ctx *fiber.Ctx) bool {
|
||||
return ctx.Method() != fiber.MethodPost
|
||||
},
|
||||
Header: "X-Custom-Header",
|
||||
Generator: func() string {
|
||||
// Custom ID generator
|
||||
app.Use(middleware.RequestID(func() string {
|
||||
return "1234567890"
|
||||
},
|
||||
}))
|
||||
}))
|
||||
|
||||
// Custom Config
|
||||
app.Use(middleware.RequestID(middleware.RequestIDConfig{
|
||||
Next: func(ctx *fiber.Ctx) bool {
|
||||
return ctx.Method() != fiber.MethodPost
|
||||
},
|
||||
Header: "X-Custom-Header",
|
||||
Generator: func() string {
|
||||
return "1234567890"
|
||||
},
|
||||
}))
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Signatures
|
||||
|
@ -14,13 +14,18 @@ import (
|
||||
|
||||
After you initiate your Fiber app, you can use the following possibilities:
|
||||
```go
|
||||
handler := func(ctx *fiber.Ctx) {
|
||||
ctx.Send("Hello, World 👋!")
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
|
||||
handler := func(ctx *fiber.Ctx) {
|
||||
ctx.Send("Hello, World 👋!")
|
||||
}
|
||||
|
||||
// Wrap the handler with a timeout
|
||||
app.Get("/foo", middleware.Timeout(handler, 5 * time.Second))
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
// Wrap the handler with a timeout
|
||||
app.Get("/foo", middleware.Timeout(handler, 5 * time.Second))
|
||||
|
||||
```
|
||||
|
||||
### Signatures
|
||||
|
Loading…
x
Reference in New Issue
Block a user