package
1.2.0
Repository: https://github.com/klauspost/goa.git
Documentation: pkg.go.dev

# README

goa Middlewares

The middleware package provides middlewares that do not depend on additional packages other than the ones already used by goa. These middlewares provide functionality that is useful to most microservices:

  • LogRequest enables logging of incoming requests and corresponding responses. The log format is entirely configurable. The default format logs the request HTTP method, path and parameters as well as the corresponding action and controller names. It also logs the request duration and response length. It also logs the request payload if the DEBUG log level is enabled. Finally if the RequestID middleware is mounted LogRequest logs the unique request ID with each log entry.

  • LogResponse logs the content of the response body if the DEBUG log level is enabled.

  • RequestID injects a unique ID in the request context. This ID is used by the logger and can be used by controller actions as well. The middleware looks for the ID in the RequestIDHeader header and if not found creates one.

  • Recover recover panics and logs the panic object and backtrace.

  • Timeout sets a deadline in the request context. Controller actions may subscribe to the context channel to get notified when the timeout expires.

  • RequireHeader checks for the presence of a header in the request with a value matching a given regular expression. If the header is absent or does not match the regexp the middleware sends a HTTP response with a given HTTP status.

Other middlewares listed below are provided as separate Go packages.

Gzip

Package gzip contributed by @tylerb adds the ability to compress response bodies using gzip format as specified in RFC 1952.

Security

package security contains middleware that should be used in conjunction with the security DSL.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

ContextParentSpanID returns the parent span ID extracted from the given context if any, the empty string otherwise.
ContextRequestID extracts the Request ID from the context.
ContextSpanID returns the span ID extracted from the given context if any, the empty string otherwise.
ContextTraceID returns the trace ID extracted from the given context if any, the empty string otherwise.
ErrorHandler turns a Go error into an HTTP response.
LogRequest creates a request logger middleware.
LogResponse creates a response logger middleware.
Recover is a middleware that recovers panics and maps them to errors.
RequestID is a middleware that injects a request ID into the context of each request.
RequestIDWithHeader behaves like the middleware RequestID, but it takes the request id header as the (first) argument.
RequestIDWithHeaderAndLengthLimit behaves like the middleware RequestID, but it takes the request id header as the (first) argument and a length limit for truncation of the request header value if it exceeds a reasonable length.
RequireHeader requires a request header to match a value pattern.
Timeout sets a global timeout for all controller actions.
TraceDoer wraps a goa client Doer and sets the trace headers so that the downstream service may properly retrieve the parent span ID and trace ID.
Tracer returns a middleware that initializes the trace information in the context.
WithTrace returns a context containing the given trace, span and parent span IDs.

# Constants

DefaultRequestIDLengthLimit is the default maximum length for the request ID header value.
RequestIDHeader is the name of the header used to transmit the request ID.

# Variables

ParentSpanIDHeader is the name of the HTTP request header containing the parent span ID if any.
TraceIDHeader is the name of the HTTP request header containing the current TraceID if any.

# Type aliases

No description provided by the author