middleware

package
v1.8.31 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 14 Imported by: 50

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BasicAuthConfigDefault = BasicAuthConfig{
	Skip:  nil,
	Users: map[string]string{},
	Realm: "Restricted",
}

BasicAuthConfigDefault is the default BasicAuth middleware config.

View Source
var CorsConfigDefault = CORSConfig{
	Skip:         nil,
	AllowOrigins: []string{"*"},
	AllowMethods: []string{
		http.MethodGet,
		http.MethodPost,
		http.MethodHead,
		http.MethodPut,
		http.MethodDelete,
		http.MethodPatch,
	},
}

CorsConfigDefault is the defaul Cors middleware config.

View Source
var HelmetConfigDefault = HelmetConfig{
	Skip:               nil,
	XSSProtection:      "1; mode=block",
	ContentTypeNosniff: "nosniff",
	XFrameOptions:      "SAMEORIGIN",
}

HelmetConfigDefault is the defaul Helmet middleware config.

View Source
var LimiterConfigDefault = LimiterConfig{
	Skip:       nil,
	Timeout:    60,
	Max:        10,
	Message:    "Too many requests, please try again later.",
	StatusCode: 429,
	Key: func(c *fiber.Ctx) string {
		return c.IP()
	},
}

LimiterConfigDefault is the defaul Limiter middleware config.

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

LoggerConfigDefault is the defaul Logger middleware config.

View Source
var RequestIDConfigDefault = RequestIDConfig{
	Skip: nil,
	Generator: func() string {
		return uuid.New().String()
	},
}

RequestIDConfigDefault is the default RequestID middleware config.

Functions

func BasicAuth added in v1.8.1

func BasicAuth(config ...BasicAuthConfig) func(*fiber.Ctx)

BasicAuth ...

func Cors

func Cors(config ...CORSConfig) func(*fiber.Ctx)

Cors ...

func Helmet

func Helmet(config ...HelmetConfig) func(*fiber.Ctx)

Helmet ...

func Limiter added in v1.3.3

func Limiter(config ...LimiterConfig) func(*fiber.Ctx)

Limiter ...

func Logger added in v1.3.3

func Logger(config ...LoggerConfig) func(*fiber.Ctx)

Logger ...

func Recover added in v1.8.2

func Recover(handle ...func(*fiber.Ctx, error)) func(*fiber.Ctx)

Recover ...

func RequestID added in v1.8.1

func RequestID(config ...RequestIDConfig) func(*fiber.Ctx)

RequestID adds an indentifier to the request using the `X-Request-ID` header

Types

type BasicAuthConfig added in v1.8.1

type BasicAuthConfig struct {
	// Skip defines a function to skip middleware.
	// Optional. Default: nil
	Skip func(*fiber.Ctx) bool
	// Users defines the allowed credentials
	// Required. Default: map[string]string{}
	Users map[string]string
	// Realm is a string to define realm attribute of BasicAuth.
	// Optional. Default: "Restricted".
	Realm string
}

BasicAuthConfig defines the config for BasicAuth middleware

type CORSConfig added in v1.8.1

type CORSConfig struct {
	Skip func(*fiber.Ctx) bool
	// Optional. Default value []string{"*"}.
	AllowOrigins []string
	// Optional. Default value []string{"GET","POST","HEAD","PUT","DELETE","PATCH"}
	AllowMethods []string
	// Optional. Default value []string{}.
	AllowHeaders []string
	// Optional. Default value false.
	AllowCredentials bool
	// Optional. Default value []string{}.
	ExposeHeaders []string
	// Optional. Default value 0.
	MaxAge int
}

CORSConfig ...

type HelmetConfig added in v1.8.1

type HelmetConfig struct {
	// Skip defines a function to skip middleware.
	// Optional. Default: nil
	Skip func(*fiber.Ctx) bool
	// XSSProtection
	// Optional. Default value "1; mode=block".
	XSSProtection string
	// ContentTypeNosniff
	// Optional. Default value "nosniff".
	ContentTypeNosniff string
	// XFrameOptions
	// Optional. Default value "SAMEORIGIN".
	// Possible values: "SAMEORIGIN", "DENY", "ALLOW-FROM uri"
	XFrameOptions string
	// HSTSMaxAge
	// Optional. Default value 0.
	HSTSMaxAge int
	// HSTSExcludeSubdomains
	// Optional. Default value false.
	HSTSExcludeSubdomains bool
	// ContentSecurityPolicy
	// Optional. Default value "".
	ContentSecurityPolicy string
	// CSPReportOnly
	// Optional. Default value false.
	CSPReportOnly bool
	// HSTSPreloadEnabled
	// Optional.  Default value false.
	HSTSPreloadEnabled bool
	// ReferrerPolicy
	// Optional. Default value "".
	ReferrerPolicy string
}

HelmetConfig ...

type LimiterConfig added in v1.8.1

type LimiterConfig struct {
	Skip func(*fiber.Ctx) bool
	// Timeout in seconds on how long to keep records of requests in memory
	// Default: 60
	Timeout int
	// Max number of recent connections during `Timeout` seconds before sending a 429 response
	// Default: 10
	Max int
	// Message
	// default: "Too many requests, please try again later."
	Message string
	// StatusCode
	// Default: 429 Too Many Requests
	StatusCode int
	// Key allows to use a custom handler to create custom keys
	// Default: func(c *fiber.Ctx) string {
	//   return c.IP()
	// }
	Key func(*fiber.Ctx) string
	// Handler is called when a request hits the limit
	// Default: func(c *fiber.Ctx) {
	//   c.Status(cfg.StatusCode).SendString(cfg.Message)
	// }
	Handler func(*fiber.Ctx)
}

LimiterConfig ...

type LoggerConfig added in v1.8.1

type LoggerConfig struct {
	// Skip defines a function to skip middleware.
	// Optional. Default: nil
	Skip func(*fiber.Ctx) bool
	// Format defines the logging format with defined variables
	// Optional. Default: "${time} - ${ip} - ${method} ${path}\t${ua}\n"
	// Possible values: time, ip, url, host, method, path, protocol
	// referer, ua, header:<key>, query:<key>, formform:<key>, cookie:<key>
	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 ...

type RequestIDConfig added in v1.8.1

type RequestIDConfig struct {
	// Skip defines a function to skip middleware.
	// Optional. Default: nil
	Skip func(*fiber.Ctx) bool
	// Generator defines a function to generate an ID.
	// Optional. Default: func() string {
	//   return uuid.New().String()
	// }
	Generator func() string
}

RequestIDConfig defines the config for RequestID middleware

Jump to

Keyboard shortcuts

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