Source File
context.go
Belonging Package
go.opentelemetry.io/otel/api/correlation
package correlation
import (
)
type correlationsType struct{}
type SetHookFunc func(context.Context) context.Context
type GetHookFunc func(context.Context, Map) Map
var correlationsKey = &correlationsType{}
type correlationsData struct {
m Map
setHook SetHookFunc
getHook GetHookFunc
}
func ( correlationsData) () bool {
return .setHook == nil && .getHook == nil
}
type hookKind int
const (
hookKindSet hookKind = iota
hookKindGet
)
func ( *correlationsData) ( hookKind, SetHookFunc, GetHookFunc) {
switch {
case hookKindSet:
.setHook =
case hookKindGet:
.getHook =
}
}
func ( context.Context, SetHookFunc) context.Context {
return contextWithHook(, hookKindSet, , nil)
}
func ( context.Context, GetHookFunc) context.Context {
return contextWithHook(, hookKindGet, nil, )
}
func ( context.Context, hookKind, SetHookFunc, GetHookFunc) context.Context {
switch v := .Value(correlationsKey).(type) {
case correlationsData:
.overrideHook(, , )
if .isHookless() {
return context.WithValue(, correlationsKey, .m)
}
return context.WithValue(, correlationsKey, )
case Map:
return contextWithOneHookAndMap(, , , , )
default:
:= NewEmptyMap()
return contextWithOneHookAndMap(, , , , )
}
}
func ( context.Context, hookKind, SetHookFunc, GetHookFunc, Map) context.Context {
:= correlationsData{m: }
.overrideHook(, , )
if .isHookless() {
return
}
return context.WithValue(, correlationsKey, )
}
func ( context.Context) (context.Context, SetHookFunc, GetHookFunc) {
switch v := .Value(correlationsKey).(type) {
case correlationsData:
return context.WithValue(, correlationsKey, .m), .setHook, .getHook
default:
return , nil, nil
}
}
func ( context.Context, Map) context.Context {
switch v := .Value(correlationsKey).(type) {
case correlationsData:
.m =
= context.WithValue(, correlationsKey, )
if .setHook != nil {
= .setHook()
}
return
default:
return context.WithValue(, correlationsKey, )
}
}
func ( context.Context) Map {
switch v := .Value(correlationsKey).(type) {
case correlationsData:
if .getHook != nil {
return .getHook(, .m)
}
return .m
case Map:
return
default:
return NewEmptyMap()
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |