Documentation ¶
Index ¶
- Constants
- Variables
- func Compress(options ...interface{}) fiber.Handler
- func CompressWithConfig(config CompressConfig) fiber.Handler
- func Favicon(file ...string) fiber.Handler
- func FileSystem(options ...interface{}) fiber.Handler
- func Logger(options ...interface{}) fiber.Handler
- func LoggerWithConfig(config LoggerConfig) fiber.Handler
- func Recover() fiber.Handler
- func RequestID(options ...interface{}) fiber.Handler
- func RequestIDWithConfig(config RequestIDConfig) 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 ( 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:" )
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: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n", TimeFormat: "15:04:05", Output: os.Stdout, }
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 CompressWithConfig ¶ added in v1.11.0
func CompressWithConfig(config CompressConfig) fiber.Handler
CompressWithConfig is deprecated, please use Compress instead
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(timeFormat string)
- Logger(config LoggerConfig)
func LoggerWithConfig ¶ added in v1.11.0
func LoggerWithConfig(config LoggerConfig) fiber.Handler
LoggerWithConfig is deprecated, please use Logger instead
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)
func RequestIDWithConfig ¶ added in v1.11.0
func RequestIDWithConfig(config RequestIDConfig) fiber.Handler
RequestIDWithConfig is deprecated, please use RequestID instead
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 // // - time // - ip // - ips // - url // - host // - method // - path // - protocol // - route // - referer // - ua // - latency // - status // - body // - error // - bytesSent // - bytesReceived // - header:<key> // - query:<key> // - form:<key> // - cookie:<key> // // Optional. Default: ${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n Format string // TimeFormat https://programming.guide/go/format-parse-string-time-date-example.html // // Optional. Default: 15:04:05 TimeFormat string // Output is a writter where logs are written // // Default: os.Stderr Output io.Writer }
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.