MCPcopy
hub / github.com/rs/zerolog / AccessHandler

Function AccessHandler

hlog/hlog.go:292–303  ·  hlog/hlog.go::AccessHandler

AccessHandler returns a handler that call f after each request.

(f func(r *http.Request, status, size int, duration time.Duration))

Source from the content-addressed store, hash-verified

290
291// AccessHandler returns a handler that call f after each request.
292func AccessHandler(f func(r *http.Request, status, size int, duration time.Duration)) func(next http.Handler) http.Handler {
293 return func(next http.Handler) http.Handler {
294 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
295 start := time.Now()
296 lw := mutil.WrapWriter(w)
297 defer func() {
298 f(r, lw.Status(), lw.BytesWritten(), time.Since(start))
299 }()
300 next.ServeHTTP(lw, r)
301 })
302 }
303}
304
305// HostHandler adds the request's host as a field to the context's logger
306// using fieldKey as field key. If trimPort is set to true, then port is

Callers

nothing calls this directly

Calls 3

WrapWriterFunction · 0.92
StatusMethod · 0.65
BytesWrittenMethod · 0.65

Tested by

no test coverage detected