Documentation
¶
Index ¶
- Constants
- func CustomHTTPErrorHandler(err error, c echo.Context)
- func TemplateRequest(c echo.Context, t *template.Template) (err error)
- type AllMiddlewares
- type AuthMiddleware
- type AuthOption
- type ContextMiddleware
- type ContextOption
- type DDMiddleware
- type DDOption
- type LoggingMiddleware
- type LoggingOption
- type ParamCheckerMiddleware
- type ParamOption
- type RateLimitMiddleware
- type RateLimitOption
- type RequestWrapperMiddleware
- type ResponseTemplateWriter
- type ResponseWrapperMiddleware
- type TokenMiddleware
- type TokenOption
Constants ¶
const (
// UUIDRegex represents a UUID regular expression
UUIDRegex = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
)
Variables ¶
This section is empty.
Functions ¶
func CustomHTTPErrorHandler ¶
func CustomHTTPErrorHandler(err error, c echo.Context)
CustomHTTPErrorHandler handles errors by both printing them nicely and sending them to elasticsearch
func TemplateRequest ¶
TemplateRequest proxies the Request Body from a context through the given template
Types ¶
type AllMiddlewares ¶
type AllMiddlewares struct { Auth *AuthMiddleware BodyLimitConfig emiddleware.BodyLimitConfig Context *ContextMiddleware DDTracer *DDMiddleware Logging *LoggingMiddleware ParamChecker *ParamCheckerMiddleware RateLimit *RateLimitMiddleware Token *TokenMiddleware External []echo.MiddlewareFunc }
AllMiddlewares is a struct with one configured Middleware of each type
func InitMiddlewares ¶
func InitMiddlewares(conf configurer.ConfigReader) (am *AllMiddlewares)
InitMiddlewares configures default middlewares, and returns them all as a struct for later configuration
func (*AllMiddlewares) UseMiddlewares ¶
func (am *AllMiddlewares) UseMiddlewares(e middlewareUser)
UseMiddlewares registers all of the middlewares for use
type AuthMiddleware ¶
type AuthMiddleware struct {
// contains filtered or unexported fields
}
AuthMiddleware provides a middleware that verifies required authentication for endpoints.
func NewAuthMiddleware ¶
func NewAuthMiddleware(cfg configurer.ConfigReader, opts ...AuthOption) *AuthMiddleware
NewAuthMiddleware is a variadic constructor for an AuthMiddleware.
func (*AuthMiddleware) Wrapper ¶
func (am *AuthMiddleware) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper is a pass through function for handlers that implicitly performs additional business logic per request. In this case, we're wrapping an existing echo middleware with the right config.
type AuthOption ¶
type AuthOption func(*AuthMiddleware)
AuthOption provides the client a callback that is used to dynamically specify attributes for an AuthMiddleware.
func WithActiveTokenRequest ¶
func WithActiveTokenRequest(method string, component string, path string, payload interface{}) AuthOption
WithActiveTokenRequest configures the request to an external component for token validation
func WithAuthClaims ¶
func WithAuthClaims(claims jwt.Claims) AuthOption
WithAuthClaims is used for specifying the Logger for an AuthMiddleware.
func WithAuthSkipper ¶
func WithAuthSkipper(skipper func(c context.EMFContext) bool) AuthOption
WithAuthSkipper configures the AuthMiddleware Skipper function. The Skipper function determines which endpoints skip authentication
type ContextMiddleware ¶
type ContextMiddleware struct {
// contains filtered or unexported fields
}
ContextMiddleware provides a middleware that performs tasks common to all endpoints.
func NewContextMiddleware ¶
func NewContextMiddleware(cfg configurer.ConfigReader, opts ...ContextOption) *ContextMiddleware
NewContextMiddleware is a variadic constructor for a ContextMiddleware.
func (*ContextMiddleware) Wrapper ¶
func (cm *ContextMiddleware) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper is the middleware function itself which redefines the echo.Context to our Custom object
type ContextOption ¶
type ContextOption func(*ContextMiddleware)
ContextOption provides the client a callback that is used to dynamically specify attributes for a ContextMiddleware.
func WithContextClient ¶
func WithContextClient(client *http.Client) ContextOption
WithContextClient is used to specify the HTTP Client for the Requester to use.
type DDMiddleware ¶
type DDMiddleware struct {
// contains filtered or unexported fields
}
DDMiddleware provides a middleware that performs tasks common to all endpoints.
func NewDDTracerMiddleware ¶
func NewDDTracerMiddleware(enabled bool, opts ...DDOption) *DDMiddleware
NewDDTracerMiddleware is a variadic constructor for a DDTrace.
func (*DDMiddleware) Middleware ¶
func (dd *DDMiddleware) Middleware(next echo.HandlerFunc) echo.HandlerFunc
Middleware returns echo middleware which will trace incoming requests.
type DDOption ¶
type DDOption func(*DDMiddleware)
DDOption represents an option that can be passed to Middleware.
func WithAgentHost ¶
WithAgentHost specifies a custom agent host.
func WithAnalytics ¶
WithAnalytics enables Trace Analytics for all started spans.
func WithServiceName ¶
WithServiceName sets the given service name for the system.
type LoggingMiddleware ¶
type LoggingMiddleware struct {
// contains filtered or unexported fields
}
LoggingMiddleware provides a middleware that performs tasks common to all endpoints.
func NewLoggingMiddleware ¶
func NewLoggingMiddleware(opts ...LoggingOption) *LoggingMiddleware
NewLoggingMiddleware is a variadic constructor for a LoggingMiddleware.
func (*LoggingMiddleware) Wrapper ¶
func (lm *LoggingMiddleware) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper is a pass through function for handlers that implicitly performs additional business logic per request.
type LoggingOption ¶
type LoggingOption func(*LoggingMiddleware)
LoggingOption provides the client a callback that is used to dynamically specify attributes for a LoggingMiddleware.
func ElasticSearchOption ¶
func ElasticSearchOption(isElasticSearch bool) LoggingOption
ElasticSearchOption takes in the ElasticSearch config boolean, and sets the LoggingMiddleware accordingly
type ParamCheckerMiddleware ¶
type ParamCheckerMiddleware struct {
// contains filtered or unexported fields
}
ParamCheckerMiddleware is used for checking that the parameters are valid UUIDs or integers.
func NewParamCheckerMiddleware ¶
func NewParamCheckerMiddleware(opts ...ParamOption) *ParamCheckerMiddleware
NewParamCheckerMiddleware is a variadic constructor for a TokenMiddleware.
func (ParamCheckerMiddleware) Wrapper ¶
func (pcm ParamCheckerMiddleware) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper is middleware for checking that the parameters are valid UUIDs or integers.
type ParamOption ¶
type ParamOption func(*ParamCheckerMiddleware)
ParamOption provides the client a callback that is used to dynamically specify attributes for a ParamCheckerMiddleware.
func WithRegex ¶
func WithRegex(regex string) ParamOption
WithRegex is used for specifying the regex to check params against.
type RateLimitMiddleware ¶
type RateLimitMiddleware struct {
// contains filtered or unexported fields
}
RateLimitMiddleware provides a middleware that verifies required authentication for endpoints.
func NewRateLimitMiddleware ¶
func NewRateLimitMiddleware(opts ...RateLimitOption) *RateLimitMiddleware
NewRateLimitMiddleware is a variadic constructor for a RateLimitMiddleware.
func (*RateLimitMiddleware) Wrapper ¶
func (rlm *RateLimitMiddleware) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper is a pass through function for handlers that implicitly performs additional business logic per request.
type RateLimitOption ¶
type RateLimitOption func(*RateLimitMiddleware)
RateLimitOption provides the client a callback that is used to dynamically specify attributes for a RateLimitMiddleware.
func WithLimiter ¶
func WithLimiter(lmt *limiter.Limiter) RateLimitOption
WithLimiter is used for specifying the rate to limit.
type RequestWrapperMiddleware ¶
type RequestWrapperMiddleware struct {
// contains filtered or unexported fields
}
RequestWrapperMiddleware turns the TemplateRequest function into a Middleware
func WrapRequest ¶
func WrapRequest(t *template.Template) RequestWrapperMiddleware
WrapRequest is the constructor for a RequestWrapperMiddleware
func (RequestWrapperMiddleware) Wrapper ¶
func (rwm RequestWrapperMiddleware) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper satisfies the Middleware interface for a RequestWrapperMiddleware
type ResponseTemplateWriter ¶
type ResponseTemplateWriter struct {
// contains filtered or unexported fields
}
ResponseTemplateWriter implements the http.ResponseWriter interface and allows a go template to be executed against the Response body
func NewResponseTemplateWriter ¶
func NewResponseTemplateWriter( rw http.ResponseWriter, t *template.Template, responseObject interface{}, ) ResponseTemplateWriter
NewResponseTemplateWriter returns an http.ResponseWriter that executes the given template on the http response body, which should be the same type as responseObject
func (ResponseTemplateWriter) Header ¶
func (tw ResponseTemplateWriter) Header() http.Header
Header calls the original http ResponseWriter Header method
func (ResponseTemplateWriter) Wrapper ¶
func (tw ResponseTemplateWriter) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper satisfies the Middleware interface for a ResponseWrapperMiddleware
func (ResponseTemplateWriter) Write ¶
func (tw ResponseTemplateWriter) Write(p []byte) (i int, e error)
Write overrides the Write method by first piping the response data through a JSON Decoder and then into the Template
func (ResponseTemplateWriter) WriteHeader ¶
func (tw ResponseTemplateWriter) WriteHeader(statusCode int)
WriteHeader calls the original http ResponseWriter WriteHeader method
type ResponseWrapperMiddleware ¶
type ResponseWrapperMiddleware = ResponseTemplateWriter
ResponseWrapperMiddleware extends the ResponseTemplateWriter into a Middleware
func WrapResponse ¶
func WrapResponse(t *template.Template, responseObject interface{}) ResponseWrapperMiddleware
WrapResponse is the constructor for a ResponseWrapperMiddleware
type TokenMiddleware ¶
type TokenMiddleware struct {
// contains filtered or unexported fields
}
TokenMiddleware provides a middleware that verifies required authentication for endpoints.
func NewTokenMiddleware ¶
func NewTokenMiddleware(opts ...TokenOption) *TokenMiddleware
NewTokenMiddleware is a variadic constructor for a TokenMiddleware.
func (*TokenMiddleware) Wrapper ¶
func (tokenMid *TokenMiddleware) Wrapper(next echo.HandlerFunc) echo.HandlerFunc
Wrapper is a pass through function for handlers that implicitly performs additional business logic per request.
type TokenOption ¶
type TokenOption func(*TokenMiddleware)
TokenOption provides the client a callback that is used to dynamically specify attributes for a TokenMiddleware.
func WithTokenVerifier ¶
func WithTokenVerifier(verify func(*jwt.Token) bool) TokenOption
WithTokenVerifier is used for specifying the verify function for JWT Tokens.