MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / WithClientInfoFromContext

Function WithClientInfoFromContext

pkg/events/options.go:90–106  ·  view source on GitHub ↗

WithClientInfoFromContext returns an option that extracts the UserAgent and the RemoteIP from the request context.

()

Source from the content-addressed store, hash-verified

88
89// WithClientInfoFromContext returns an option that extracts the UserAgent and the RemoteIP from the request context.
90func WithClientInfoFromContext() Option {
91 return optionFunc(func(e *event) {
92 if p, ok := peer.FromContext(e.ctx); ok && p.Addr != nil && p.Addr.String() != "pipe" {
93 if host, _, err := net.SplitHostPort(p.Addr.String()); err == nil {
94 e.innerEvent.RemoteIp = host
95 }
96 }
97 md := rpcmetadata.FromIncomingContext(e.ctx)
98 if md.XForwardedFor != "" {
99 xff := strings.Split(md.XForwardedFor, ",")
100 e.innerEvent.RemoteIp = strings.Trim(xff[0], " ")
101 }
102 if md := rpcmetadata.FromIncomingContext(e.ctx); md.UserAgent != "" {
103 e.innerEvent.UserAgent = md.UserAgent
104 }
105 })
106}
107
108// DefinitionOption is like Option, but applies to the definition instead.
109type DefinitionOption interface {

Callers 15

observability.goFile · 0.92
observability.goFile · 0.92
TestNewFunction · 0.92
user_registry.goFile · 0.92
gateway_access.goFile · 0.92

Calls 3

FromIncomingContextFunction · 0.92
optionFuncFuncType · 0.70
StringMethod · 0.65

Tested by 1

TestNewFunction · 0.74