middleware

package module
v0.0.0-...-794a47f Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: MIT Imports: 8 Imported by: 0

README

echo-middleware

Echo V3 middleware

  • cache: page cache for request. for now only in-memory cache
  • heartbeat: get a quick /ping response to client
  • nocache: set http header for no cache
  • request id: set request id to request and response

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ByteBufferPool byte buffer pool
	ByteBufferPool = &byteBufferPool{
		pool: &sync.Pool{
			New: func() interface{} {
				return new(bytes.Buffer)
			},
		},
	}
)
View Source
var (

	// DefaultNoCacheConfig is the default nocache middleware config.
	DefaultNoCacheConfig = NoCacheConfig{
		Skipper: emw.DefaultSkipper,
	}
)
View Source
var (
	// DefaultRequestIDConfig is the default RequestID middleware config.
	DefaultRequestIDConfig = RequestIDConfig{
		Skipper:   ewm.DefaultSkipper,
		Generator: generator,
	}
)

Functions

func Heartbeat

func Heartbeat(endpoint string) echo.MiddlewareFunc

Heartbeat endpoint middleware useful to setting up a path like `/ping` that load balancers or uptime testing external services can make a request before hitting any routes. It's also convenient to place this above ACL middlewares as well.

func NoCache

func NoCache() echo.MiddlewareFunc

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 NoCacheWithConfig

func NoCacheWithConfig(config NoCacheConfig) echo.MiddlewareFunc

NoCacheWithConfig returns a nocache middleware with config.

func RequestID

func RequestID() echo.MiddlewareFunc

RequestID returns a X-Request-ID middleware.

func RequestIDWithConfig

func RequestIDWithConfig(config RequestIDConfig) echo.MiddlewareFunc

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

Types

type NoCacheConfig

type NoCacheConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper emw.Skipper
}

NoCacheConfig defines the config for nocache middleware.

type RequestIDConfig

type RequestIDConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper ewm.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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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