middleware

package
v5.0.0-...-03972fd Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultStaticConfig is the default Static middleware config.
	DefaultStaticConfig = StaticConfig{
		Skipper: DefaultSkipper,
		Index:   "index.html",
	}
)

Functions

func DefaultSkipper

func DefaultSkipper(ctx echo.Context) bool

DefaultSkipper returns false which processes the middleware.

func NoCache

func NoCache(h http.Handler) http.Handler

NoCache is a simple piece of middleware that sets a number of HTTP headers to prevent a router (or subrouter) from being cached by an upstream proxy and/or client.

As per http://wiki.nginx.org/HttpProxyModule - NoCache sets:

Expires: Thu, 01 Jan 1970 00:00:00 UTC
Cache-Control: no-cache, private, max-age=0
X-Accel-Expires: 0
Pragma: no-cache (for HTTP/1.0 proxies/clients)

func PageCache

func PageCache(
	e *echo.Echo,
	class string,
	dependencies func(c echo.Context) (map[string]string, error),
	duration time.Duration,
) func(http.Handler) http.Handler

Cached is middleware for cache whole html page.

func Recoverer

func Recoverer(
	logger log.Logger,
) func(http.Handler) http.Handler

Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible. Recoverer prints a request ID if one is provided.

Alternatively, look at https://github.com/pressly/lg middleware pkgs.

func Static

func Static(root string) func(http.Handler) http.Handler

Static returns a Static middleware to serves static content from the provided root directory.

func StaticWithConfig

func StaticWithConfig(config StaticConfig) func(http.Handler) http.Handler

StaticWithConfig returns a Static middleware with config. See `Static()`.

func WithDynamic

func WithDynamic(
	e *echo.Echo,
) func(http.Handler) http.Handler

WithDynamic is a middleware that added supports dynamic content in the COMPLEX mode. NOTE. Do not forget to switch the flag e.Complex = true.

Types

type BeforeFunc

type BeforeFunc func(echo.Context)

BeforeFunc defines a function which is executed just before the middleware.

type Skipper

type Skipper func(echo.Context) bool

Skipper defines a function to skip middleware. Returning true skips processing the middleware.

type StaticConfig

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

	// Root directory from where the static content is served.
	// Required.
	Root string `yaml:"root"`

	// Index file for serving a directory.
	// Optional. Default value "index.html".
	Index string `yaml:"index"`

	// Enable HTML5 mode by forwarding all not-found requests to root so that
	// SPA (single-page application) can handle the routing.
	// Optional. Default value false.
	HTML5 bool `yaml:"html5"`

	// Enable directory browsing.
	// Optional. Default value false.
	Browse bool `yaml:"browse"`
}

StaticConfig defines the config for Static middleware.

Jump to

Keyboard shortcuts

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