Documentation ¶
Overview ¶
Package correlation enhances the context of requests with correlation and user identity.
Index ¶
- Variables
- func GetContextWithCorrelationParam(ctx context.Context, c *CorrelationParam) context.Context
- func GetContextWithUserIdentifier(ctx context.Context, c *UserIdentifier) context.Context
- func GetHeader(ctx context.Context) map[string]string
- func SetCorrelationHeader(ctx context.Context, req *http.Request)
- type CorrelationParam
- type UserIdentifier
Constants ¶
This section is empty.
Variables ¶
var ( ContextKeyCorrelation contextKey = contextKey("ContextKeyCorrelation") ContextKeyCustomerIdentifier contextKey = contextKey("ContextKeyCustomerIdentifier") )
Functions ¶
func GetContextWithCorrelationParam ¶
func GetContextWithCorrelationParam(ctx context.Context, c *CorrelationParam) context.Context
GetContextWithCorrelationParam returns a context.Context with the provided CorrelationParam.
func GetContextWithUserIdentifier ¶
func GetContextWithUserIdentifier(ctx context.Context, c *UserIdentifier) context.Context
GetContextWithUserIdentifier returns a context.Context with the provided UserIdentifier.
Types ¶
type CorrelationParam ¶
type CorrelationParam struct { CorrelationID string `header:"x-correlation-id" body:"correlationId"` ScenarioID *string `header:"x-scenario-id,omitempty" body:"scenarioId,omitempty"` SessionID *string `header:"x-session-id,omitempty" body:"sessionId,omitempty"` ScenarioName *string `header:"x-scenario-name,omitempty" body:"scenarioName,omitempty"` }
CorrelationParam defines a context object for correlation.
func ExtractCorrelationParam ¶
func ExtractCorrelationParam(ctx context.Context) *CorrelationParam
ExtractCorrelationParam retrieves the CorrelationParam stored within the context.Context.
func NewCorrelationParam ¶
func NewCorrelationParam(serviceName string) *CorrelationParam
NewCorrelationParam creates a new CorrelationParam with a given service name.
func (*CorrelationParam) GetHeader ¶
func (c *CorrelationParam) GetHeader() map[string]string
GetHeader encodes CorrelationParam into a map[string]string with header struct tags.
func (*CorrelationParam) GetPayload ¶
func (c *CorrelationParam) GetPayload() map[string]string
GetPayload encodes CorrelationParam into a map[string]string with body struct tags.
func (*CorrelationParam) LoadFromHeader ¶
func (c *CorrelationParam) LoadFromHeader(header map[string]string) error
LoadFromHeader extracts CorrelationParam from a map[string]string with header struct tags.
type UserIdentifier ¶
type UserIdentifier struct { UserID *string `header:"x-user-id,omitempty" body:"userId,omitempty"` AppUserID *string `header:"x-app-user-id,omitempty" body:"appUserID,omitempty"` EntityID *string `header:"x-entity-id,omitempty" body:"entityId,omitempty"` }
UserIdentifier defines a context object for customer identification.
func ExtractUserIdentifier ¶
func ExtractUserIdentifier(ctx context.Context) *UserIdentifier
ExtractUserIdentifier retrieves the UserIdentifier stored within the context.Context.
func (*UserIdentifier) GetHeader ¶
func (c *UserIdentifier) GetHeader() map[string]string
GetHeader encodes UserIdentifier into a map[string]string with header struct tags.
func (*UserIdentifier) GetPayload ¶
func (c *UserIdentifier) GetPayload() map[string]string
GetPayload encodes UserIdentifier into a map[string]string with body struct tags.
func (*UserIdentifier) LoadFromHeader ¶
func (c *UserIdentifier) LoadFromHeader(header map[string]string) error
LoadFromHeader extracts UserIdentifier from a map[string]string with header struct tags.