middleware

package
v1.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 13 Imported by: 50

Documentation

Index

Constants

View Source
const (
	CompressLevelDisabled        = -1
	CompressLevelDefault         = 0
	CompressLevelBestSpeed       = 1
	CompressLevelBestCompression = 2
)

Compression levels

View Source
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

View Source
var CompressConfigDefault = CompressConfig{
	Next:  nil,
	Level: CompressLevelDefault,
}

CompressConfigDefault is the default config

View Source
var LoggerConfigDefault = LoggerConfig{
	Next:       nil,
	Format:     "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n",
	TimeFormat: "15:04:05",
	Output:     os.Stderr,
}

LoggerConfigDefault is the default config

View Source
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

func Compress(level ...int) fiber.Handler

Compress is the default initiator allowing to pass the compression level It supports brotli, gzip and deflate compression The same order is used to check against the Accept-Encoding header

func CompressWithConfig added in v1.11.0

func CompressWithConfig(config CompressConfig) fiber.Handler

CompressWithConfig allows you to pass an CompressConfig It supports brotli, gzip and deflate compression The same order is used to check against the Accept-Encoding header

func Favicon added in v1.11.0

func Favicon(file ...string) fiber.Handler

Favicon adds an UUID indentifier to the request

func Logger added in v1.3.3

func Logger(format ...string) fiber.Handler

Logger is the default initiator allowing to pass a log format

func LoggerWithConfig added in v1.11.0

func LoggerWithConfig(config LoggerConfig) fiber.Handler

LoggerWithConfig allows you to pass an CompressConfig

func Recover added in v1.8.2

func Recover() fiber.Handler

Recover will recover from panics and calls the ErrorHandler

func RequestID added in v1.8.1

func RequestID(header ...string) fiber.Handler

RequestID adds an UUID indentifier to the request

func RequestIDWithConfig added in v1.11.0

func RequestIDWithConfig(config RequestIDConfig) fiber.Handler

RequestIDWithConfig allows you to pass a custom config

Types

type CompressConfig added in v1.11.0

type CompressConfig struct {
	// Next defines a function to skip this middleware.
	Next func(ctx *fiber.Ctx) bool
	// Compression level for brotli, gzip and deflate
	Level int
}

CompressConfig defines the config for Compress middleware.

type LoggerConfig added in v1.8.1

type LoggerConfig struct {
	// Next defines a function to skip this middleware.
	Next func(ctx *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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL