Documentation
¶
Overview ¶
Package middleware provides HTTP handler useful decorators.
Index ¶
- Variables
- func AccessLog(next http.Handler, logger *slog.Logger, callback AccessRequestCallbeck) http.Handler
- func CorrelationID(next http.Handler, makeCorrelationID xtransport.CorrelationIDFactory) http.Handler
- func Recover(next http.Handler, logger *slog.Logger) http.Handler
- type AccessRequestCallbeck
Constants ¶
This section is empty.
Variables ¶
View Source
var AccessLevel slog.Level = slog.LevelError + 4
AccessLevel is the log level used for access logs.
Functions ¶
func AccessLog ¶
AccessLog is a decorator/middleware that extracts/ads a correlation id from/to request/response.
func CorrelationID ¶
func CorrelationID(next http.Handler, makeCorrelationID xtransport.CorrelationIDFactory) http.Handler
CorrelationID is a decorator/middleware that extracts/ads a correlation id from/to request/response.
Types ¶
type AccessRequestCallbeck ¶
AccessRequestCallback is a function type through which you can specify a callback to to indicate whether a request should be logged or not, and to modify the request before logging.
Usage example:
func myAccessRequestCallback(r *http.Request) bool {
if r.URL.Path == "/health" {
return false // skip logging for health endpoint
}
if r.PathValue("secretToken") != "" {
// obfuscate secret token in the request path
newPath := strings.ReplaceAll(r.URL.Path, r.PathValue("secretToken"), r.PathValue("secretToken")[:4]+"****")
r.URL.Path = newPath
}
return true // log the request
}
Click to show internal directories.
Click to hide internal directories.