Documentation
¶
Index ¶
- Variables
- func AJAX(handler echo.HandlerFuncs) echo.MiddlewareFunc
- func AJAXWithConfig(config AJAXConfig) echo.MiddlewareFunc
- func AddTrailingSlash() echo.MiddlewareFuncd
- func AddTrailingSlashWithConfig(config TrailingSlashConfig) echo.MiddlewareFuncd
- func BasicAuth(fn BasicValidateFunc, skipper ...echo.Skipper) echo.MiddlewareFunc
- func BodyLimit(limit string) echo.MiddlewareFunc
- func BodyLimitWithConfig(config BodyLimitConfig) echo.MiddlewareFunc
- func CORS() echo.MiddlewareFunc
- func CORSWithConfig(config CORSConfig) echo.MiddlewareFunc
- func CSRF() echo.MiddlewareFuncd
- func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFuncd
- func FuncMap(funcMap map[string]interface{}, skipper ...echo.Skipper) echo.MiddlewareFunc
- func GetDefaultLogWriter() io.Writer
- func Gzip(config ...*GzipConfig) echo.MiddlewareFunc
- func GzipWithConfig(config *GzipConfig) echo.MiddlewareFunc
- func HTTPSNonWWWRedirect() echo.MiddlewareFunc
- func HTTPSNonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
- func HTTPSRedirect() echo.MiddlewareFunc
- func HTTPSRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
- func HTTPSWWWRedirect() echo.MiddlewareFunc
- func HTTPSWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
- func KeyAuth(fn KeyAuthValidator) echo.MiddlewareFuncd
- func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFuncd
- func Log(recv ...func(*VisitorInfo)) echo.MiddlewareFunc
- func LogWithConfig(config LogConfig) echo.MiddlewareFunc
- func LogWithWriter(writer io.Writer, recv ...func(*VisitorInfo)) echo.MiddlewareFunc
- func MaxAllowed(n int) echo.MiddlewareFunc
- func MethodOverride() echo.MiddlewareFuncd
- func MethodOverrideWithConfig(config MethodOverrideConfig) echo.MiddlewareFuncd
- func NeedQuoteMeta(r rune) bool
- func NoCache(skippers ...echo.Skipper) echo.MiddlewareFuncd
- func NonWWWRedirect() echo.MiddlewareFunc
- func NonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
- func Proxy(balancer ProxyBalancer) echo.MiddlewareFuncd
- func ProxyHTTPCustomHandler(t ProxyTargeter, c echo.Context) http.Handler
- func ProxyWithConfig(config ProxyConfig) echo.MiddlewareFuncd
- func QueryParamToRegexpRule(query string, disableColonParam bool) (pathRegexp string, newPath string, regexpRules []string, ...)
- func Queue() echo.MiddlewareFunc
- func QueueWithConfig(config QueueConfig) echo.MiddlewareFunc
- func Recover() echo.Middleware
- func RecoverWithConfig(config RecoverConfig) echo.MiddlewareFunc
- func ReleaseVisitorInfo(v *VisitorInfo)
- func RemoveTrailingSlash() echo.MiddlewareFuncd
- func RemoveTrailingSlashWithConfig(config TrailingSlashConfig) echo.MiddlewareFuncd
- func RequestID() echo.MiddlewareFuncd
- func RequestIDWithConfig(config RequestIDConfig) echo.MiddlewareFuncd
- func Rewrite(rules map[string]string) echo.MiddlewareFuncd
- func RewriteWithConfig(config RewriteConfig) echo.MiddlewareFuncd
- func Secure() echo.MiddlewareFuncd
- func SecureWithConfig(config SecureConfig) echo.MiddlewareFuncd
- func SetNoCacheHeader(c echo.Context)
- func Static(options ...*StaticOptions) echo.MiddlewareFunc
- func UnrewriteWithConfig(config RewriteConfig) echo.MiddlewareFuncd
- func Validate(generator func() echo.Validator, skipper ...echo.Skipper) echo.MiddlewareFunc
- func ValidateRewriteRule(urlPath, newPath string, disableParam bool) error
- func WWWRedirect() echo.MiddlewareFunc
- func WWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
- type AJAXConfig
- type BasicValidateFunc
- type BodyLimitConfig
- type CORSConfig
- type CSRFConfig
- type GzipConfig
- type KeyAuthConfig
- type KeyAuthValidator
- type LogConfig
- type MethodOverrideConfig
- type MethodOverrideGetter
- type ProxyBalancer
- type ProxyConfig
- type ProxyHandler
- type ProxyTarget
- type ProxyTargeter
- type QueueConfig
- type RecoverConfig
- type RedirectConfig
- type RequestIDConfig
- type RewriteConfig
- func (c *RewriteConfig) Add(urlPath, newPath string) *RewriteConfig
- func (c *RewriteConfig) Delete(urlPath string) *RewriteConfig
- func (c *RewriteConfig) Init() *RewriteConfig
- func (c *RewriteConfig) Reverse(urlPath string) string
- func (c *RewriteConfig) Rewrite(urlPath string) string
- func (c *RewriteConfig) Set(urlPath, newPath string) *RewriteConfig
- type RewriteRegExp
- type SecureConfig
- type StaticOptions
- type TrailingSlashConfig
- type VisitorInfo
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultCSRFConfig is the default CSRF middleware config. DefaultCSRFConfig = CSRFConfig{ Skipper: echo.DefaultSkipper, TokenLength: 32, TokenLookup: "header:" + echo.HeaderXCSRFToken, ContextKey: "csrf", SessionName: "_csrf", } ErrCSRFTokenInvalid = errors.New("csrf token is invalid") ErrCSRFTokenIsEmpty = errors.New("empty csrf token") ErrCSRFTokenIsEmptyInForm = fmt.Errorf("%w in form param", ErrCSRFTokenIsEmpty) ErrCSRFTokenIsEmptyInQuery = fmt.Errorf("%w in query param", ErrCSRFTokenIsEmpty) )
var ( // DefaultProxyConfig is the default Proxy middleware config. DefaultProxyConfig = ProxyConfig{ Skipper: echo.DefaultSkipper, Handler: DefaultProxyHandler, Rewrite: DefaultRewriteConfig, ContextKey: "target", } // DefaultProxyHandler Proxy Handler DefaultProxyHandler ProxyHandler = func(t ProxyTargeter, c echo.Context) error { var key string switch { case c.IsWebsocket(): key = `raw` case c.Header(echo.HeaderAccept) == echo.MIMEEventStream: key = `sse` default: key = `default` } if h, ok := DefaultProxyHandlers[key]; ok { resp := c.Response().StdResponseWriter() req := c.Request().StdRequest() h(t, c).ServeHTTP(resp, req) } return nil } // DefaultProxyHandlers default preset handlers DefaultProxyHandlers = map[string]func(ProxyTargeter, echo.Context) http.Handler{ `raw`: func(t ProxyTargeter, c echo.Context) http.Handler { return proxyRaw(t, c) }, `sse`: func(t ProxyTargeter, c echo.Context) http.Handler { return proxyHTTPWithFlushInterval(t, c) }, `default`: func(t ProxyTargeter, c echo.Context) http.Handler { return proxyHTTP(t, c) }, } )
var ( // ErrQueueTimeout is thrown when the request waits more than QueueTimeout to be queued ErrQueueTimeout = echo.NewHTTPError(http.StatusTooManyRequests, "queue limit reached") // ErrWorkerTimeout is thrown when the request waits more than WorkerTimeout for a worker to start processing it ErrWorkerTimeout = echo.NewHTTPError(http.StatusRequestTimeout, "request took too long to process") )
errors
var DefaultAJAXConfig = AJAXConfig{ Skipper: echo.DefaultSkipper, Handler: echo.HandlerFuncs{}, ParamName: `op`, OnlyAJAX: true, }
var ( // DefaultCORSConfig is the default CORS middleware config. DefaultCORSConfig = CORSConfig{ Skipper: echo.DefaultSkipper, AllowOrigins: []string{"*"}, AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.POST, echo.DELETE}, } )
var ( // DefaultGzipConfig is the default Gzip middleware config. DefaultGzipConfig = &GzipConfig{ Skipper: echo.DefaultSkipper, Level: -1, } )
var ( // DefaultKeyAuthConfig is the default KeyAuth middleware config. DefaultKeyAuthConfig = KeyAuthConfig{ Skipper: echo.DefaultSkipper, KeyLookup: "header:" + echo.HeaderAuthorization, AuthScheme: "Bearer", } )
var DefaultLogWriter = GetDefaultLogWriter()
var ( // DefaultMethodOverrideConfig is the default MethodOverride middleware config. DefaultMethodOverrideConfig = MethodOverrideConfig{ Skipper: echo.DefaultSkipper, Getter: MethodFromHeader(echo.HeaderXHTTPMethodOverride), } )
var DefaultProxyHTTPDirector = func(target *url.URL, c echo.Context) func(req *http.Request) { targetQuery := target.RawQuery return func(req *http.Request) { if req.Body == nil { req.Body = c.Request().Body() } req.URL.Scheme = target.Scheme req.URL.Host = target.Host req.URL.Path, req.URL.RawPath = joinURLPath(target, req.URL) if targetQuery == "" || req.URL.RawQuery == "" { req.URL.RawQuery = targetQuery + req.URL.RawQuery } else { req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery } if _, ok := req.Header["User-Agent"]; !ok { req.Header.Set("User-Agent", "") } } }
DefaultProxyHTTPDirector default director
var DefaultQueueConfig = QueueConfig{ Skipper: echo.DefaultSkipper, QueueSize: 100, Workers: runtime.GOMAXPROCS(0), QueueTimeout: 30 * time.Second, WorkerTimeout: 10 * time.Second, }
DefaultQueueConfig defines default values for QueueConfig
var ( // DefaultRecoverConfig is the default Recover middleware config. DefaultRecoverConfig = RecoverConfig{ Skipper: echo.DefaultSkipper, StackSize: 4 << 10, DisableStackAll: false, DisablePrintStack: false, } )
var DefaultRedirectConfig = RedirectConfig{ Skipper: echo.DefaultSkipper, Code: http.StatusMovedPermanently, }
DefaultRedirectConfig is the default Redirect middleware config.
var ( // DefaultRequestIDConfig is the default RequestID middleware config. DefaultRequestIDConfig = RequestIDConfig{ Skipper: echo.DefaultSkipper, Generator: generator, } )
var ( // DefaultRewriteConfig is the default Rewrite middleware config. DefaultRewriteConfig = RewriteConfig{ Skipper: echo.DefaultSkipper, } )
var ( // DefaultSecureConfig is the default Secure middleware config. DefaultSecureConfig = SecureConfig{ Skipper: echo.DefaultSkipper, XSSProtection: "1; mode=block", ContentTypeNosniff: "nosniff", XFrameOptions: "SAMEORIGIN", } )
var ( // DefaultTrailingSlashConfig is the default TrailingSlash middleware config. DefaultTrailingSlashConfig = TrailingSlashConfig{ Skipper: echo.DefaultSkipper, } )
var ListDirTemplate = `` /* 629-byte string literal not displayed */
Functions ¶
func AJAX ¶ added in v1.16.6
func AJAX(handler echo.HandlerFuncs) echo.MiddlewareFunc
AJAX wraps the given handler with default AJAX configuration and returns a middleware function. The middleware ensures the request is AJAX by checking the X-Requested-With header. Use AJAXWithConfig for custom configuration options.
func AJAXWithConfig ¶ added in v1.16.6
func AJAXWithConfig(config AJAXConfig) echo.MiddlewareFunc
AJAXWithConfig returns a middleware function that handles AJAX operations based on the provided config. The middleware checks for AJAX requests and processes operations specified in the form parameter. If Skipper returns true or OnlyAJAX is true and the request is not AJAX, it skips the middleware. Config parameters are merged with defaults if not provided.
func AddTrailingSlash ¶
func AddTrailingSlash() echo.MiddlewareFuncd
AddTrailingSlash returns a root level (before router) middleware which adds a trailing slash to the request `URL#Path`.
Usage `Echo#Pre(AddTrailingSlash())`
func AddTrailingSlashWithConfig ¶
func AddTrailingSlashWithConfig(config TrailingSlashConfig) echo.MiddlewareFuncd
AddTrailingSlashWithConfig returns a AddTrailingSlash middleware with config. See `AddTrailingSlash()`.
func BasicAuth ¶
func BasicAuth(fn BasicValidateFunc, skipper ...echo.Skipper) echo.MiddlewareFunc
BasicAuth returns an HTTP basic authentication middleware.
For valid credentials it calls the next handler. For invalid credentials, it sends "401 - Unauthorized" response.
func BodyLimit ¶
func BodyLimit(limit string) echo.MiddlewareFunc
BodyLimit returns a body limit 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 body limit is determined based on both `Content-Length` request header and actual content read, which makes it super secure. Limit can be specified as `4x` or `4xB`, where x is one of the multiple from K, M, G, T or P.
func BodyLimitWithConfig ¶
func BodyLimitWithConfig(config BodyLimitConfig) echo.MiddlewareFunc
BodyLimitWithConfig returns a body limit middleware from config. See: `BodyLimit()`.
func CORS ¶
func CORS() echo.MiddlewareFunc
CORS returns a cross-origin HTTP request (CORS) middleware. See https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS
func CORSWithConfig ¶
func CORSWithConfig(config CORSConfig) echo.MiddlewareFunc
CORSFromConfig returns a CORS middleware from config. See `CORS()`.
func CSRF ¶
func CSRF() echo.MiddlewareFuncd
CSRF returns a Cross-Site Request Forgery (CSRF) middleware. See: https://en.wikipedia.org/wiki/Cross-site_request_forgery
func CSRFWithConfig ¶
func CSRFWithConfig(config CSRFConfig) echo.MiddlewareFuncd
CSRFWithConfig returns a CSRF middleware with config. See `CSRF()`.
func FuncMap ¶
func FuncMap(funcMap map[string]interface{}, skipper ...echo.Skipper) echo.MiddlewareFunc
func GetDefaultLogWriter ¶ added in v1.5.0
func Gzip ¶
func Gzip(config ...*GzipConfig) echo.MiddlewareFunc
Gzip returns a middleware which compresses HTTP response using gzip compression scheme.
func GzipWithConfig ¶
func GzipWithConfig(config *GzipConfig) echo.MiddlewareFunc
GzipWithConfig return Gzip middleware with config. See: `Gzip()`.
func HTTPSNonWWWRedirect ¶ added in v1.3.7
func HTTPSNonWWWRedirect() echo.MiddlewareFunc
HTTPSNonWWWRedirect redirects http requests to https non www. For example, http://www.labstack.com will be redirect to https://labstack.com.
Usage `Echo#Pre(HTTPSNonWWWRedirect())`
func HTTPSNonWWWRedirectWithConfig ¶ added in v1.3.7
func HTTPSNonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
HTTPSNonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config. See `HTTPSNonWWWRedirect()`.
func HTTPSRedirect ¶
func HTTPSRedirect() echo.MiddlewareFunc
HTTPSRedirect redirects http requests to https. For example, http://labstack.com will be redirect to https://labstack.com.
Usage `Echo#Pre(HTTPSRedirect())`
func HTTPSRedirectWithConfig ¶
func HTTPSRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
HTTPSRedirectWithConfig returns an HTTPSRedirect middleware with config. See `HTTPSRedirect()`.
func HTTPSWWWRedirect ¶
func HTTPSWWWRedirect() echo.MiddlewareFunc
HTTPSWWWRedirect redirects http requests to https www. For example, http://labstack.com will be redirect to https://www.labstack.com.
Usage `Echo#Pre(HTTPSWWWRedirect())`
func HTTPSWWWRedirectWithConfig ¶
func HTTPSWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
HTTPSWWWRedirectWithConfig returns an HTTPSRedirect middleware with config. See `HTTPSWWWRedirect()`.
func KeyAuth ¶ added in v1.3.5
func KeyAuth(fn KeyAuthValidator) echo.MiddlewareFuncd
KeyAuth returns an KeyAuth middleware.
For valid key it calls the next handler. For invalid key, it sends "401 - Unauthorized" response. For missing key, it sends "400 - Bad Request" response.
func KeyAuthWithConfig ¶ added in v1.3.5
func KeyAuthWithConfig(config KeyAuthConfig) echo.MiddlewareFuncd
KeyAuthWithConfig returns an KeyAuth middleware with config. See `KeyAuth()`.
func Log ¶
func Log(recv ...func(*VisitorInfo)) echo.MiddlewareFunc
func LogWithConfig ¶ added in v1.7.11
func LogWithConfig(config LogConfig) echo.MiddlewareFunc
func LogWithWriter ¶ added in v1.5.0
func LogWithWriter(writer io.Writer, recv ...func(*VisitorInfo)) echo.MiddlewareFunc
func MaxAllowed ¶
func MaxAllowed(n int) echo.MiddlewareFunc
MaxAllowed limits simultaneous requests; can help with high traffic load
func MethodOverride ¶
func MethodOverride() echo.MiddlewareFuncd
MethodOverride returns a MethodOverride middleware. MethodOverride middleware checks for the overridden method from the request and uses it instead of the original method.
For security reasons, only `POST` method can be overridden.
func MethodOverrideWithConfig ¶
func MethodOverrideWithConfig(config MethodOverrideConfig) echo.MiddlewareFuncd
MethodOverrideWithConfig returns a MethodOverride middleware with config. See: `MethodOverride()`.
func NeedQuoteMeta ¶ added in v1.7.4
func NoCache ¶ added in v1.1.0
func NoCache(skippers ...echo.Skipper) echo.MiddlewareFuncd
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 NonWWWRedirect ¶
func NonWWWRedirect() echo.MiddlewareFunc
NonWWWRedirect redirects www requests to non www. For example, http://www.labstack.com will be redirect to http://labstack.com.
Usage `Echo#Pre(NonWWWRedirect())`
func NonWWWRedirectWithConfig ¶
func NonWWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
NonWWWRedirectWithConfig returns an HTTPSRedirect middleware with config. See `NonWWWRedirect()`.
func Proxy ¶ added in v1.3.5
func Proxy(balancer ProxyBalancer) echo.MiddlewareFuncd
Proxy returns a Proxy middleware.
Proxy middleware forwards the request to upstream server using a configured load balancing technique.
func ProxyHTTPCustomHandler ¶ added in v1.6.0
func ProxyHTTPCustomHandler(t ProxyTargeter, c echo.Context) http.Handler
ProxyHTTPCustomHandler 自定义处理(支持传递body)
func ProxyWithConfig ¶ added in v1.3.5
func ProxyWithConfig(config ProxyConfig) echo.MiddlewareFuncd
ProxyWithConfig returns a Proxy middleware with config. See: `Proxy()`
func QueryParamToRegexpRule ¶ added in v1.6.0
func Queue ¶ added in v1.6.0
func Queue() echo.MiddlewareFunc
Queue returns a queue middleware
e := echo.New()
e.GET("/queue", func(c echo.Context) error {
return c.String(http.StatusOK, "test")
}, middleware.Queue())
func QueueWithConfig ¶ added in v1.6.0
func QueueWithConfig(config QueueConfig) echo.MiddlewareFunc
QueueWithConfig returns a queue middleware
e := echo.New()
config := middleware.QueueConfig{
Skipper: DefaultSkipper,
QueueSize: 2,
Workers: 1,
QueueTimeout: 20 * time.Second,
WorkerTimeout: 10 * time.Second,
}
e.GET("/queue", func(c echo.Context) error {
return c.String(http.StatusOK, "test")
}, middleware.QueueWithConfig(config))
func Recover ¶
func Recover() echo.Middleware
Recover returns a middleware which recovers from panics anywhere in the chain and handles the control to the centralized HTTPErrorHandler.
func RecoverWithConfig ¶ added in v1.1.0
func RecoverWithConfig(config RecoverConfig) echo.MiddlewareFunc
RecoverWithConfig returns a Recover middleware with config. See: `Recover()`.
func ReleaseVisitorInfo ¶ added in v1.6.0
func ReleaseVisitorInfo(v *VisitorInfo)
func RemoveTrailingSlash ¶
func RemoveTrailingSlash() echo.MiddlewareFuncd
RemoveTrailingSlash returns a root level (before router) middleware which removes a trailing slash from the request URI.
Usage `Echo#Pre(RemoveTrailingSlash())`
func RemoveTrailingSlashWithConfig ¶
func RemoveTrailingSlashWithConfig(config TrailingSlashConfig) echo.MiddlewareFuncd
RemoveTrailingSlashWithConfig returns a RemoveTrailingSlash middleware with config. See `RemoveTrailingSlash()`.
func RequestID ¶ added in v1.6.0
func RequestID() echo.MiddlewareFuncd
RequestID returns a X-Request-ID middleware.
func RequestIDWithConfig ¶ added in v1.6.0
func RequestIDWithConfig(config RequestIDConfig) echo.MiddlewareFuncd
RequestIDWithConfig returns a X-Request-ID middleware with config.
func Rewrite ¶ added in v1.3.5
func Rewrite(rules map[string]string) echo.MiddlewareFuncd
Rewrite returns a Rewrite middleware.
Rewrite middleware rewrites the URL path based on the provided rules.
func RewriteWithConfig ¶ added in v1.3.5
func RewriteWithConfig(config RewriteConfig) echo.MiddlewareFuncd
RewriteWithConfig returns a Rewrite middleware with config. See: `Rewrite()`.
func Secure ¶
func Secure() echo.MiddlewareFuncd
Secure returns a Secure middleware. Secure middleware provides protection against cross-site scripting (XSS) attack, content type sniffing, clickjacking, insecure connection and other code injection attacks.
func SecureWithConfig ¶
func SecureWithConfig(config SecureConfig) echo.MiddlewareFuncd
SecureWithConfig returns a Secure middleware with config. See: `Secure()`.
func SetNoCacheHeader ¶ added in v1.1.0
func Static ¶
func Static(options ...*StaticOptions) echo.MiddlewareFunc
func UnrewriteWithConfig ¶ added in v1.6.0
func UnrewriteWithConfig(config RewriteConfig) echo.MiddlewareFuncd
func ValidateRewriteRule ¶ added in v1.6.0
func WWWRedirect ¶
func WWWRedirect() echo.MiddlewareFunc
WWWRedirect redirects non www requests to www. For example, http://labstack.com will be redirect to http://www.labstack.com.
Usage `Echo#Pre(WWWRedirect())`
func WWWRedirectWithConfig ¶
func WWWRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc
WWWRedirectWithConfig returns an HTTPSRedirect middleware with config. See `WWWRedirect()`.
Types ¶
type AJAXConfig ¶ added in v1.16.6
type BasicValidateFunc ¶
type BodyLimitConfig ¶
type BodyLimitConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
// Maximum allowed size for a request body, it can be specified
// as `4x` or `4xB`, where x is one of the multiple from K, M, G, T or P.
Limit string `json:"limit"`
// contains filtered or unexported fields
}
BodyLimitConfig defines the config for body limit middleware.
type CORSConfig ¶
type CORSConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper
// AllowOrigin defines a list of origins that may access the resource.
// Optional with default value as []string{"*"}.
AllowOrigins []string
// AllowMethods defines a list methods allowed when accessing the resource.
// This is used in response to a preflight request.
// Optional with default value as `DefaultCORSConfig.AllowMethods`.
AllowMethods []string
// AllowHeaders defines a list of request headers that can be used when
// making the actual request. This in response to a preflight request.
// Optional with default value as []string{}.
AllowHeaders []string
// AllowCredentials indicates whether or not the response to the request
// can be exposed when the credentials flag is true. When used as part of
// a response to a preflight request, this indicates whether or not the
// actual request can be made using credentials.
// Optional with default value as false.
AllowCredentials bool
// ExposeHeaders defines a whitelist headers that clients are allowed to
// access.
// Optional with default value as []string{}.
ExposeHeaders []string
// MaxAge indicates how long (in seconds) the results of a preflight request
// can be cached.
// Optional with default value as 0.
MaxAge int
}
CORSConfig defines the config for CORS middleware.
type CSRFConfig ¶
type CSRFConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
// TokenLength is the length of the generated token.
TokenLength uint8 `json:"token_length"`
// TokenLookup is a string in the form of "<source>:<key>" that is used
// to extract token from the request.
// Optional. Default value "header:X-CSRF-Token".
// Possible values:
// - "header:<name>"
// - "form:<name>"
// - "query:<name>"
TokenLookup string `json:"token_lookup"`
// Context key to store generated CSRF token into context.
// Optional. Default value "csrf".
ContextKey string `json:"context_key"`
// Name of the CSRF session. This session will store CSRF token.
// Optional. Default value "_csrf".
SessionName string `json:"session_name"`
}
CSRFConfig defines the config for CSRF middleware.
type GzipConfig ¶
type GzipConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
// Gzip compression level.
// Optional. Default value -1.
Level int `json:"level"`
}
GzipConfig defines the config for Gzip middleware.
type KeyAuthConfig ¶ added in v1.3.5
type KeyAuthConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper
// KeyLookup is a string in the form of "<source>:<name>" that is used
// to extract key from the request.
// Optional. Default value "header:Authorization".
// Possible values:
// - "header:<name>"
// - "query:<name>"
// - "form:<name>"
KeyLookup string `yaml:"key_lookup"`
// AuthScheme to be used in the Authorization header.
// Optional. Default value "Bearer".
AuthScheme string
// Validator is a function to validate key.
// Required.
Validator KeyAuthValidator
}
KeyAuthConfig defines the config for KeyAuth middleware.
type KeyAuthValidator ¶ added in v1.3.5
KeyAuthValidator defines a function to validate KeyAuth credentials.
type LogConfig ¶ added in v1.7.11
type LogConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
Writer io.Writer `json:"-"`
Execute func(*VisitorInfo) `json:"-"`
}
type MethodOverrideConfig ¶
type MethodOverrideConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper
// Getter is a function that gets overridden method from the request.
// Optional. Default values MethodFromHeader(echo.HeaderXHTTPMethodOverride).
Getter MethodOverrideGetter
}
MethodOverrideConfig defines the config for MethodOverride middleware.
type MethodOverrideGetter ¶
MethodOverrideGetter is a function that gets overridden method from the request
func MethodFromForm ¶
func MethodFromForm(param string) MethodOverrideGetter
MethodFromForm is a `MethodOverrideGetter` that gets overridden method from the form parameter.
func MethodFromHeader ¶
func MethodFromHeader(header string) MethodOverrideGetter
MethodFromHeader is a `MethodOverrideGetter` that gets overridden method from the request header.
func MethodFromQuery ¶
func MethodFromQuery(param string) MethodOverrideGetter
MethodFromQuery is a `MethodOverrideGetter` that gets overridden method from the query parameter.
type ProxyBalancer ¶ added in v1.3.5
type ProxyBalancer interface {
AddTarget(ProxyTargeter) bool
RemoveTarget(string) bool
Next(echo.Context) ProxyTargeter
}
ProxyBalancer defines an interface to implement a load balancing technique.
func NewRandomBalancer ¶ added in v1.3.5
func NewRandomBalancer(targets []ProxyTargeter) ProxyBalancer
NewRandomBalancer returns a random proxy balancer.
func NewRoundRobinBalancer ¶ added in v1.3.5
func NewRoundRobinBalancer(targets []ProxyTargeter) ProxyBalancer
NewRoundRobinBalancer returns a round-robin proxy balancer.
type ProxyConfig ¶ added in v1.3.5
type ProxyConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
// Balancer defines a load balancing technique.
// Required.
Balancer ProxyBalancer `json:"-"`
Handler ProxyHandler `json:"-"`
Rewrite RewriteConfig
// Context key to store selected ProxyTarget into context.
// Optional. Default value "target".
ContextKey string
}
ProxyConfig defines the config for Proxy middleware.
type ProxyHandler ¶ added in v1.3.5
type ProxyHandler func(t ProxyTargeter, c echo.Context) error
ProxyHandler defines an interface to implement a proxy handler.
type ProxyTarget ¶ added in v1.3.5
ProxyTarget defines the upstream target.
func (*ProxyTarget) GetFlushInterval ¶ added in v1.6.0
func (t *ProxyTarget) GetFlushInterval() time.Duration
func (*ProxyTarget) GetMeta ¶ added in v1.6.0
func (t *ProxyTarget) GetMeta(_ echo.Context) echo.Store
func (*ProxyTarget) GetName ¶ added in v1.6.0
func (t *ProxyTarget) GetName() string
func (*ProxyTarget) SetFlushInterval ¶ added in v1.6.0
func (t *ProxyTarget) SetFlushInterval(interval time.Duration)
type ProxyTargeter ¶ added in v1.6.0
type QueueConfig ¶ added in v1.6.0
type QueueConfig struct {
Skipper echo.Skipper
QueueSize int
Workers int
QueueTimeout time.Duration
WorkerTimeout time.Duration
}
QueueConfig defines the configuration for the queue
type RecoverConfig ¶ added in v1.1.0
type RecoverConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper
// Size of the stack to be printed.
// Optional. Default value 4KB.
StackSize int `json:"stack_size"`
// DisableStackAll disables formatting stack traces of all other goroutines
// into buffer after the trace for the current goroutine.
// Optional. Default value false.
DisableStackAll bool `json:"disable_stack_all"`
// DisablePrintStack disables printing stack trace.
// Optional. Default value as false.
DisablePrintStack bool `json:"disable_print_stack"`
}
RecoverConfig defines the config for Recover middleware.
type RedirectConfig ¶
type RedirectConfig struct {
// Skipper defines a function to skip middleware.
echo.Skipper
// Status code to be used when redirecting the request.
// Optional. Default value http.StatusMovedPermanently.
Code int `yaml:"code"`
}
RedirectConfig defines the config for Redirect middleware.
type RequestIDConfig ¶ added in v1.6.0
type RequestIDConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper
// Generator defines a function to generate an ID.
// Optional. Default value random.String(32).
Generator func() string
// RequestIDHandler defines a function which is executed for a request id.
RequestIDHandler func(echo.Context, string)
}
RequestIDConfig defines the config for RequestID middleware.
type RewriteConfig ¶ added in v1.3.5
type RewriteConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
// Rules defines the URL path rewrite rules. The values captured in asterisk can be
// retrieved by index e.g. $1, $2 and so on.
// Example:
// "/old": "/new",
// "/api/*": "/$1",
// "/js/*": "/public/javascripts/$1",
// "/users/*/orders/*": "/user/$1/order/$2",
// "/users/:id": "/user/$1",
// "/match/<name:[0-9]+>": "/user/$1",
// Required.
Rules map[string]string `json:"rules"`
DisableColonParam bool
// contains filtered or unexported fields
}
RewriteConfig defines the config for Rewrite middleware.
func (*RewriteConfig) Add ¶ added in v1.3.5
func (c *RewriteConfig) Add(urlPath, newPath string) *RewriteConfig
Add rule
func (*RewriteConfig) Delete ¶ added in v1.3.5
func (c *RewriteConfig) Delete(urlPath string) *RewriteConfig
Delete rule
func (*RewriteConfig) Init ¶ added in v1.3.5
func (c *RewriteConfig) Init() *RewriteConfig
Init Initialize
func (*RewriteConfig) Reverse ¶ added in v1.6.0
func (c *RewriteConfig) Reverse(urlPath string) string
Reverse url
func (*RewriteConfig) Rewrite ¶ added in v1.3.5
func (c *RewriteConfig) Rewrite(urlPath string) string
Rewrite url
func (*RewriteConfig) Set ¶ added in v1.3.5
func (c *RewriteConfig) Set(urlPath, newPath string) *RewriteConfig
Set rule
type RewriteRegExp ¶ added in v1.6.0
type SecureConfig ¶
type SecureConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
// XSSProtection provides protection against cross-site scripting attack (XSS)
// by setting the `X-XSS-Protection` header.
// Optional. Default value "1; mode=block".
XSSProtection string `json:"xss_protection"`
// ContentTypeNosniff provides protection against overriding Content-Type
// header by setting the `X-Content-Type-Options` header.
// Optional. Default value "nosniff".
ContentTypeNosniff string `json:"content_type_nosniff"`
// XFrameOptions can be used to indicate whether or not a browser should
// be allowed to render a page in a <frame>, <iframe> or <object> .
// Sites can use this to avoid clickjacking attacks, by ensuring that their
// content is not embedded into other sites.provides protection against
// clickjacking.
// Optional. Default value "SAMEORIGIN".
// Possible values:
// - "SAMEORIGIN" - The page can only be displayed in a frame on the same origin as the page itself.
// - "DENY" - The page cannot be displayed in a frame, regardless of the site attempting to do so.
// - "ALLOW-FROM uri" - The page can only be displayed in a frame on the specified origin.
XFrameOptions string `json:"x_frame_options"`
// HSTSMaxAge sets the `Strict-Transport-Security` header to indicate how
// long (in seconds) browsers should remember that this site is only to
// be accessed using HTTPS. This reduces your exposure to some SSL-stripping
// man-in-the-middle (MITM) attacks.
// Optional. Default value 0.
HSTSMaxAge int `json:"hsts_max_age"`
// HSTSExcludeSubdomains won't include subdomains tag in the `Strict Transport Security`
// header, excluding all subdomains from security policy. It has no effect
// unless HSTSMaxAge is set to a non-zero value.
// Optional. Default value false.
HSTSExcludeSubdomains bool `json:"hsts_exclude_subdomains"`
// ContentSecurityPolicy sets the `Content-Security-Policy` header providing
// security against cross-site scripting (XSS), clickjacking and other code
// injection attacks resulting from execution of malicious content in the
// trusted web page context.
// Optional. Default value "".
ContentSecurityPolicy string `json:"content_security_policy"`
}
SecureConfig defines the config for Secure middleware.
type StaticOptions ¶
type StaticOptions struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
Path string `json:"path"` //UrlPath
Root string `json:"root"`
Fallback []string `json:"fallback"`
Index string `json:"index"`
Browse bool `json:"browse"`
Template string `json:"template"`
Debug bool `json:"debug"`
FS http.FileSystem `json:"-"`
MaxAge time.Duration `json:"maxAge"`
TrimPrefix string `json:"trimPrefix"`
// contains filtered or unexported fields
}
func (*StaticOptions) AddFallback ¶ added in v1.6.0
func (s *StaticOptions) AddFallback(fallback string) *StaticOptions
func (*StaticOptions) Init ¶ added in v1.6.0
func (s *StaticOptions) Init() *StaticOptions
func (*StaticOptions) Middleware ¶ added in v1.6.0
func (s *StaticOptions) Middleware() echo.MiddlewareFunc
type TrailingSlashConfig ¶
type TrailingSlashConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper `json:"-"`
// Status code to be used when redirecting the request.
// Optional, but when provided the request is redirected using this code.
RedirectCode int `json:"redirect_code"`
}
TrailingSlashConfig defines the config for TrailingSlash middleware.
type VisitorInfo ¶ added in v1.1.1
type VisitorInfo struct {
RealIP string
Time time.Time
Elapsed time.Duration
Scheme string
Host string
URI string
Method string
UserAgent string
Referer string
RequestSize int64
ResponseSize int64
ResponseCode int
}
func AcquireVisitorInfo ¶ added in v1.6.0
func AcquireVisitorInfo() *VisitorInfo
func (*VisitorInfo) SetFromContext ¶ added in v1.6.0
func (v *VisitorInfo) SetFromContext(c echo.Context)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
example
command
|
|
|
config
Package config provides data structure to configure rate-limiter.
|
Package config provides data structure to configure rate-limiter. |
|
test
command
|
|
|
test
command
|
|
|
example
command
|
|
|
jet/test
command
|
|
|
sse/test
command
|
|
|
standard
*
|
* |
|
standard/test
command
|
|
|
test
command
|
|