Documentation
¶
Index ¶
- Constants
- func GetTraceIDFromContext(ctx context.Context) string
- type Middleware
- func (m *Middleware) Chain(middlewares ...MiddlewareFunc) MiddlewareFunc
- func (m *Middleware) ExcludePaths(paths ...string)
- func (m *Middleware) ExcludePrefixes(prefixes ...string)
- func (m *Middleware) LogRequest(next http.Handler) http.Handler
- func (m *Middleware) RecoverPanic(next http.Handler) http.Handler
- func (m *Middleware) ShouldSkip(r *http.Request) bool
- type MiddlewareFunc
Constants ¶
View Source
const ( TraceIDKey contextKey = "trace_id" UserIDKey contextKey = "user_id" RequestIDKey contextKey = "request_id" )
Variables ¶
This section is empty.
Functions ¶
func GetTraceIDFromContext ¶ added in v0.7.1
GetTraceIDFromContext returns the trace id from the context
Types ¶
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
func New ¶
func New(logger *slog.Logger) *Middleware
func (*Middleware) Chain ¶
func (m *Middleware) Chain(middlewares ...MiddlewareFunc) MiddlewareFunc
Chain combines middlewares and returns a handler. Build chain from right to left
func (*Middleware) ExcludePaths ¶ added in v0.7.0
func (m *Middleware) ExcludePaths(paths ...string)
ExcludePaths excludes exact path matches Example: mw.ExcludePaths("/health")
func (*Middleware) ExcludePrefixes ¶ added in v0.7.0
func (m *Middleware) ExcludePrefixes(prefixes ...string)
ExcludePrefixes excludes paths starting with given prefixes Example: mw.ExcludePrefixes("/health/")
func (*Middleware) LogRequest ¶
func (m *Middleware) LogRequest(next http.Handler) http.Handler
LogRequest logs HTTP requests with response details
func (*Middleware) RecoverPanic ¶
func (m *Middleware) RecoverPanic(next http.Handler) http.Handler
RecoverPanic recovers from panics
func (*Middleware) ShouldSkip ¶ added in v0.7.0
func (m *Middleware) ShouldSkip(r *http.Request) bool
shouldSkip checks if request should skip middleware
Click to show internal directories.
Click to hide internal directories.