Documentation ¶
Overview ¶
Package middleware provides some useful and commonly implemented middleware functions for StormRPC servers.
Package middleware provides some useful and commonly implemented middleware functions for StormRPC servers.
Package middleware provides some useful and commonly implemented middleware functions for StormRPC servers.
Package middleware provides some useful and commonly implemented middleware functions for StormRPC servers.
Package middleware provides some useful and commonly implemented middleware functions for StormRPC servers.
Index ¶
- Constants
- func Logger(l *slog.Logger) func(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
- func NewContextWithRequestID(ctx context.Context, id string) context.Context
- func Recoverer(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
- func RequestID(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
- func RequestIDFromContext(ctx context.Context) string
- func Tracing(tracer trace.Tracer) func(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
Constants ¶
const RequestIDHeader = "X-Request-Id"
RequestIDHeader represents the key in the header map that stores the unique request id.
Variables ¶
This section is empty.
Functions ¶
func Logger ¶
func Logger(l *slog.Logger) func(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
Logger logs request scoped information such as request id, trace information, and request duration. This middleware should be applied after RequestID, and Tracing.
func NewContextWithRequestID ¶
NewContextWithRequestID will take the original context and use it as the parent context for the returned context. The passed in id will be added to this new context.
func Recoverer ¶
func Recoverer(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
Recoverer handles recovering from a panic in other HandlerFunc's.
func RequestID ¶
func RequestID(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
RequestID extracts the value from the request header if its present. If none is present a uuid is generated to serve as the request id. This id is passed into the request context to be extracted later. It is also added to the response headers.
func RequestIDFromContext ¶
RequestIDFromContext extracts the request id from the context if one is present. If no request id is present an empty string will be returned.
func Tracing ¶
func Tracing(tracer trace.Tracer) func(next stormrpc.HandlerFunc) stormrpc.HandlerFunc
Tracing extracts the span from the incoming request headers. If none is present a new root span is created. This tracing information is also passed into the response headers.
Types ¶
This section is empty.