middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBodyLimitConfig is the default BodyLimit middleware config.
	DefaultBodyLimitConfig = middleware.BodyLimitConfig{
		Skipper: middleware.DefaultSkipper,

		Limit: "2M",
	}
)
View Source
var (
	// DefaultGzipConfig is the default Gzip middleware config.
	DefaultGzipConfig = middleware.GzipConfig{

		Skipper: func(c echo.Context) bool {
			return strings.Contains(c.Path(), "swagger") ||
				strings.Contains(c.Path(), "metrics")
		},
		Level: 5,
	}
)
View Source
var (
	// DefaultRequestIDConfig is the default RequestID middleware config.
	DefaultRequestIDConfig = RequestIDConfig{
		Skipper: middleware.DefaultSkipper,
		Generator: func() string {
			return ksuid.New().String()
		},
	}
)

Functions

func BodyLimit

func BodyLimit() echo.MiddlewareFunc

BodyLimit returns a BodyLimit middleware.

BodyLimit middleware sets the maximum allowed size for a request body, if the size exceeds the configured limit, it sends "413 - Request Entity Too Large" response. The BodyLimit is determined based on both `Content-Length` request header and actual content read, which makes it super secure.

func Gzip

func Gzip() echo.MiddlewareFunc

Gzip returns a middleware which compresses HTTP response using gzip compression scheme.

func Logger

func Logger() echo.MiddlewareFunc

Logger returns a middleware that logs HTTP requests

func RequestID

func RequestID() echo.MiddlewareFunc

RequestID returns a X-Request-ID middleware. Generate an uuid if request header X-Request-ID is empty. Prefix `be-` means it was generated by server instead of client.

func RequestIDWithConfig

func RequestIDWithConfig(config RequestIDConfig) echo.MiddlewareFunc

RequestIDWithConfig returns a X-Request-ID middleware with config.

func Secure

func Secure() echo.MiddlewareFunc

Secure returns a Secure middleware. Secure middleware provides protection against cross-site scripting (XSS) attack, content type sniffing, click-jacking, insecure connection and other code injection attacks.

Types

type RequestIDConfig

type RequestIDConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper middleware.Skipper

	// Generator defines a function to generate an ID.
	// Optional. Default value random.String(32).
	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