File tree Expand file tree Collapse file tree 7 files changed +190
-86
lines changed
Expand file tree Collapse file tree 7 files changed +190
-86
lines changed Original file line number Diff line number Diff line change 1+ # Compress
2+
3+ Compression middleware for Fiber, it supports ` deflate ` , ` gzip ` and ` brotli ` by default.
4+
5+ ### Example
6+ ``` go
7+ package main
8+
9+ import (
10+ " github.com/gofiber/fiber"
11+ " github.com/gofiber/fiber/middleware"
12+ )
13+
14+ func main () {
15+ app := fiber.New ()
16+
17+ // Default
18+ app.Use (middleware.Compress ())
19+
20+ // Custom compression level
21+ app.Use (middleware.Compress (middleware.CompressLevelBestSpeed ))
22+
23+ // Custom Config
24+ app.Use (middleware.CompressWithConfig (middleware.LoggerConfig {
25+ Next: func (ctx *fiber.Ctx ) bool {
26+ return strings.HasPrefix (ctx.Path (), " /static" )
27+ },
28+ Level: middleware.CompressLevelBestCompression ,
29+ }))
30+
31+ app.Listen (3000 )
32+ }
33+ ```
34+
35+ ### Signatures
36+ ``` go
37+ func Compress (level ...int ) fiber .Handler {}
38+ func CompressWithConfig (config CompressConfig ) fiber .Handler {}
39+ ```
40+
41+ ### Config
42+ ``` go
43+ type CompressConfig struct {
44+ // Next defines a function to skip this middleware.
45+ Next func (ctx *fiber.Ctx ) bool
46+ // Compression level for brotli, gzip and deflate
47+ Level int
48+ }
49+ ```
50+ ### Compression Levels
51+ ``` go
52+ const (
53+ CompressLevelDisabled = -1
54+ CompressLevelDefault = 0
55+ CompressLevelBestSpeed = 1
56+ CompressLevelBestCompression = 2
57+ )
58+ ```
59+
60+ ### Default Config
61+ ``` go
62+ var CompressConfigDefault = CompressConfig {
63+ Next : nil ,
64+ Level : CompressLevelDefault ,
65+ }
66+ ```
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # Logger
2+
3+ HTTP request/response logger for Fiber
4+
5+ ### Example
6+ ``` go
7+ package main
8+
9+ import (
10+ " github.com/gofiber/fiber"
11+ " github.com/gofiber/fiber/middleware"
12+ )
13+
14+ func main () {
15+ app := fiber.New ()
16+
17+ // Default
18+ app.Use (middleware.Logger ())
19+
20+ // Custom logging format
21+ app.Use (middleware.Logger (" ${method} - ${path}" ))
22+
23+ // Custom Config
24+ app.Use (middleware.LoggerWithConfig (middleware.LoggerConfig {
25+ Next: func (ctx *fiber.Ctx ) bool {
26+ return ctx.Path () != " /private"
27+ },
28+ Format: " ${method} - ${path}" ,
29+ Output: io.Writer ,
30+ }))
31+
32+ app.Listen (3000 )
33+ }
34+ ```
35+
36+ ### Signatures
37+ ``` go
38+ func Logger (format ...string ) fiber .Handler {}
39+ func LoggerWithConfig (config LoggerConfig ) fiber .Handler {}
40+ ```
41+
42+ ### Config
43+ ``` go
44+ type LoggerConfig struct {
45+ // Next defines a function to skip this middleware.
46+ Next func (ctx *fiber.Ctx ) bool
47+
48+ // Format defines the logging tags
49+ //
50+ // - time
51+ // - ip
52+ // - ips
53+ // - url
54+ // - host
55+ // - method
56+ // - path
57+ // - protocol
58+ // - route
59+ // - referer
60+ // - ua
61+ // - latency
62+ // - status
63+ // - body
64+ // - error
65+ // - bytesSent
66+ // - bytesReceived
67+ // - header:<key>
68+ // - query:<key>
69+ // - form:<key>
70+ // - cookie:<key>
71+ //
72+ // Optional. Default: ${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n
73+ Format string
74+
75+ // TimeFormat https://programming.guide/go/format-parse-string-time-date-example.html
76+ //
77+ // Optional. Default: 15:04:05
78+ TimeFormat string
79+
80+ // Output is a writter where logs are written
81+ //
82+ // Default: os.Stderr
83+ Output io.Writer
84+ }
85+ ```
86+ ### Default Config
87+ ``` go
88+ var LoggerConfigDefault = LoggerConfig {
89+ Next : nil ,
90+ Format : " ${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n " ,
91+ TimeFormat : " 15:04:05" ,
92+ Output : os.Stderr ,
93+ }
94+ ```
Original file line number Diff line number Diff line change @@ -6,20 +6,6 @@ import (
66 "github.com/gofiber/fiber"
77)
88
9- // Middleware types
10- type (
11- // RecoverConfig defines the config for Logger middleware.
12- RecoverConfig struct {
13- // Next defines a function to skip this middleware.
14- Next func (ctx * fiber.Ctx ) bool
15- }
16- )
17-
18- // RecoverConfigDefault is the default config
19- var RecoverConfigDefault = RecoverConfig {
20- Next : nil ,
21- }
22-
239// Recover will recover from panics and calls the ErrorHandler
2410func Recover () fiber.Handler {
2511 return func (ctx * fiber.Ctx ) {
Original file line number Diff line number Diff line change 1+ # Recover
2+
3+ Recover middleware recovers from panics anywhere in the stack chain and handles the control to the centralized [ ErrorHandler] ( https://docs.gofiber.io/error-handling ) .
4+
5+ ### Example
6+ ``` go
7+ package main
8+
9+ import (
10+ " github.com/gofiber/fiber"
11+ " github.com/gofiber/fiber/middleware"
12+ )
13+
14+ func main () {
15+ app := fiber.New ()
16+
17+ app.Use (middleware.Recover ())
18+
19+ app.Get (" /" , func (c *fiber.Ctx ) {
20+ panic (" normally this would crash your app" )
21+ })
22+
23+ app.Listen (3000 )
24+ }
25+ ```
26+
27+ ### Signatures
28+ ``` go
29+ func Recover () fiber .Handler {}
30+ ```
You can’t perform that action at this time.
0 commit comments