Documentation
¶
Index ¶
- Constants
- Variables
- func Compress(options ...interface{}) fiber.Handler
- func Favicon(file ...string) fiber.Handler
- func FileSystem(options ...interface{}) fiber.Handler
- func Logger(options ...interface{}) fiber.Handler
- func Pprof() fiber.Handler
- func Recover() fiber.Handler
- func RequestID(options ...interface{}) fiber.Handler
- func Timeout(handler fiber.Handler, timeout time.Duration) fiber.Handler
- type CompressConfig
- type FileSystemConfig
- type LoggerConfig
- type RequestIDConfig
Constants ¶
const ( CompressLevelDisabled = -1 CompressLevelDefault = 0 CompressLevelBestSpeed = 1 CompressLevelBestCompression = 2 )
Compression levels determine the compression complexity
const ( LoggerTagPid = "pid" LoggerTagTime = "time" LoggerTagReferer = "referer" LoggerTagProtocol = "protocol" LoggerTagIP = "ip" LoggerTagIPs = "ips" LoggerTagHost = "host" LoggerTagMethod = "method" LoggerTagPath = "path" LoggerTagURL = "url" LoggerTagUA = "ua" LoggerTagLatency = "latency" LoggerTagStatus = "status" LoggerTagBody = "body" LoggerTagBytesSent = "bytesSent" LoggerTagBytesReceived = "bytesReceived" LoggerTagRoute = "route" LoggerTagError = "error" LoggerTagHeader = "header:" LoggerTagQuery = "query:" LoggerTagForm = "form:" LoggerTagCookie = "cookie:" LoggerTagColorBlack = "black" LoggerTagColorRed = "red" LoggerTagColorGreen = "green" LoggerTagColorYellow = "yellow" LoggerTagColorBlue = "blue" LoggerTagColorMagenta = "magenta" LoggerTagColorCyan = "cyan" LoggerTagColorWhite = "white" LoggerTagColorReset = "resetColor" )
Logger variables
Variables ¶
var CompressConfigDefault = CompressConfig{ Next: nil, Level: CompressLevelDefault, }
CompressConfigDefault is the default config
var FileSystemConfigDefault = FileSystemConfig{ Next: nil, Root: nil, Index: "/index.html", Browse: false, }
FileSystemConfigDefault is the default config
var LoggerConfigDefault = LoggerConfig{ Next: nil, Format: "#${pid} - ${time} ${status} - ${latency} ${method} ${path}\n", TimeFormat: "2006/01/02 15:04:05", TimeZone: "Local", Output: os.Stderr, }
LoggerConfigDefault is the default config
var RequestIDConfigDefault = RequestIDConfig{ Next: nil, Header: fiber.HeaderXRequestID, Generator: func() string { return utils.UUID() }, }
RequestIDConfigDefault is the default config
Functions ¶
func Compress ¶ added in v1.11.0
Compress allows the following config arguments in any order:
- Compress()
- Compress(next func(*fiber.Ctx) bool)
- Compress(level int)
- Compress(config CompressConfig)
func FileSystem ¶ added in v1.12.3
FileSystem allows the following config arguments in any order:
- FileSystem(root http.FileSystem)
- FileSystem(index string)
- FileSystem(browse bool)
- FileSystem(config FileSystem)
- FileSystem(next func(*fiber.Ctx) bool)
func Logger ¶ added in v1.3.3
Logger allows the following config arguments in any order:
- Logger()
- Logger(next func(*fiber.Ctx) bool)
- Logger(output io.Writer)
- Logger(format string)
- Logger(timeZone string)
- Logger(timeFormat string)
- Logger(config LoggerConfig)
func RequestID ¶ added in v1.8.1
RequestID adds an UUID indentifier to the request
RequestID adds an UUID indentifier to the request, the following config arguments in any order:
- RequestID()
- RequestID(next func(*fiber.Ctx) bool)
- RequestID(header string)
- RequestID(generator func() string)
- RequestID(config RequestIDConfig)
Types ¶
type CompressConfig ¶ added in v1.11.0
type CompressConfig struct {
// Next defines a function to skip this middleware if returned true.
Next func(ctx *fiber.Ctx) bool
// Compression level for brotli, gzip and deflate
Level int
}
CompressConfig defines the config for Compress middleware.
type FileSystemConfig ¶ added in v1.12.3
type FileSystemConfig struct {
// Next defines a function to skip this middleware if returned true.
Next func(ctx *fiber.Ctx) bool
// Root is a FileSystem that provides access
// to a collection of files and directories.
// Required. Default: nil
Root http.FileSystem
// Index file for serving a directory.
// Optional. Default: "index.html"
Index string
// Enable directory browsing.
// Optional. Default: false
Browse bool
}
FileSystemConfig defines the config for FileSystem middleware.
type LoggerConfig ¶ added in v1.8.1
type LoggerConfig struct {
// Next defines a function to skip this middleware if returned true.
Next func(*fiber.Ctx) bool
// Format defines the logging tags
//
// - pid
// - time
// - ip
// - ips
// - url
// - host
// - method
// - methodColored
// - path
// - protocol
// - route
// - referer
// - ua
// - latency
// - status
// - statusColored
// - body
// - error
// - bytesSent
// - bytesReceived
// - header:<key>
// - query:<key>
// - form:<key>
// - cookie:<key>
//
// Optional. Default: #${pid} - ${time} ${status} - ${latency} ${method} ${path}\n
Format string
// TimeFormat https://programming.guide/go/format-parse-string-time-date-example.html
//
// Optional. Default: 2006/01/02 15:04:05
TimeFormat string
// TimeZone can be specified, such as "UTC" and "America/New_York" and "Asia/Chongqing", etc
//
// Optional. Default: Local
TimeZone string
// Output is a writter where logs are written
//
// Default: os.Stderr
Output io.Writer
// contains filtered or unexported fields
}
LoggerConfig defines the config for Logger middleware.
type RequestIDConfig ¶ added in v1.8.1
type RequestIDConfig struct {
// Next defines a function to skip this middleware.
Next func(ctx *fiber.Ctx) bool
// Header is the header key where to get/set the unique ID
// Optional. Default: X-Request-ID
Header string
// Generator defines a function to generate the unique identifier.
// Optional. Default: func() string {
// return utils.UUID()
// }
Generator func() string
}
RequestIDConfig defines the config for Logger middleware.