MCPcopy Create free account
hub / github.com/zalando/skipper / FromContext

Function FromContext

routing/context.go:24–34  ·  view source on GitHub ↗

FromContext returns value from the routing context stored in ctx. It returns value associated with the key or stores result of the defaultValue call. defaultValue may be called multiple times but only one result will be used as a default value.

(ctx context.Context, key K, defaultValue func() V)

Source from the content-addressed store, hash-verified

22// It returns value associated with the key or stores result of the defaultValue call.
23// defaultValue may be called multiple times but only one result will be used as a default value.
24func FromContext[K comparable, V any](ctx context.Context, key K, defaultValue func() V) V {
25 m, _ := ctx.Value(routingContextKey).(*sync.Map)
26
27 // https://github.com/golang/go/issues/44159#issuecomment-780774977
28 val, ok := m.Load(key)
29 if !ok {
30 val = defaultValue()
31 val, _ = m.LoadOrStore(key, val)
32 }
33 return val.(V)
34}

Callers 4

MatchMethod · 0.92
requestWithRFunction · 0.92
TestContextFunction · 0.85
TestContextDefaultFunction · 0.85

Calls

no outgoing calls

Tested by 3

requestWithRFunction · 0.74
TestContextFunction · 0.68
TestContextDefaultFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…