correlation

package
v6.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package correlation enhances the context of requests with correlation and user identity.

Index

Constants

This section is empty.

Variables

View Source
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.

func GetHeader

func GetHeader(ctx context.Context) map[string]string

GetHeader retrieves the CorrelationParam and UserIdentifier from the context.Context and marshals them with header struct tags.

func SetCorrelationHeader

func SetCorrelationHeader(ctx context.Context, req *http.Request)

SetCorrelationHeader adds the CorrelationParam and UserIdentifier from the context.Context into the http.Request Header. These values are marshalled with the header struct tag.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL