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

Function RemoteAddrHandler

hlog/hlog.go:80–92  ·  view source on GitHub ↗

RemoteAddrHandler adds the request's remote address as a field to the context's logger using fieldKey as field key.

(fieldKey string)

Source from the content-addressed store, hash-verified

78// RemoteAddrHandler adds the request's remote address as a field to the context's logger
79// using fieldKey as field key.
80func RemoteAddrHandler(fieldKey string) func(next http.Handler) http.Handler {
81 return func(next http.Handler) http.Handler {
82 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
83 if r.RemoteAddr != "" {
84 log := zerolog.Ctx(r.Context())
85 log.UpdateContext(func(c zerolog.Context) zerolog.Context {
86 return c.Str(fieldKey, r.RemoteAddr)
87 })
88 }
89 next.ServeHTTP(w, r)
90 })
91 }
92}
93
94func getHost(hostPort string) string {
95 if hostPort == "" {

Callers 3

Example_handlerFunction · 0.92
TestRemoteAddrHandlerFunction · 0.85

Calls 3

CtxFunction · 0.92
UpdateContextMethod · 0.80
StrMethod · 0.45

Tested by 3

Example_handlerFunction · 0.74
TestRemoteAddrHandlerFunction · 0.68