middleware

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CORS

type CORS struct {
	// Origin is a function that returns a value of
	// an Access-Control-Allow-Origin header. It cannot be nil.
	Origin func(r *http.Request) string
	// Headers is a function that returns a value of
	// an Access-Control-Allow-Headers header. It cannot be nil.
	Headers func(r *http.Request) string
	// Methods is a function that returns a value of
	// an Access-Control-Allow-Methods. It cannot be nil.
	Methods func(r *http.Request) string
}

CORS adds a basic support for CORS preflight requests.

func (*CORS) Handle

func (c *CORS) Handle(next http.Handler) http.Handler

Handle implements the httpserver.Middleware interface.

type HealthCheck added in v0.6.1

type HealthCheck struct {
	// Path is the path where the health check will be available.
	Path string
	// Check is a function that will be called to check the health of the service.
	Check func(r *http.Request) bool
}

HealthCheck is a middleware that checks the health of the service, it may be used with Kubernetes' liveliness probe.

It returns a 200 response if the service is healthy, otherwise it returns a 503 response.

func (*HealthCheck) Handle added in v0.6.1

func (c *HealthCheck) Handle(next http.Handler) http.Handler

Handle implements the httpserver.Middleware interface.

type Logger

type Logger struct {
	// Log is an instance of a log.Logger. It cannot be nil, otherwise code will panic.
	Log log.Logger
}

Logger prints logs for each request. If the log level is set to debug, it will print the contents of requests and responses.

func (*Logger) Handle

func (l *Logger) Handle(next http.Handler) http.Handler

Handle implements the httpserver.Middleware interface.

type Recover

type Recover struct {
	// Recover is an optional function that will be invoked during panicking.
	// It can be nil.
	Recover func(err interface{})
}

Recover recovers from panics that occurred during invoking handler's ServeHTTP method.

func (*Recover) Handle

func (c *Recover) Handle(next http.Handler) http.Handler

Handle implements the httpserver.Middleware interface.

Jump to

Keyboard shortcuts

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