headers

package
v1.10.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreHeadersInitialized

func AreHeadersInitialized(ctx context.Context) bool

AreHeadersInitialized determines whether headers have been initialized for the provided context. We assume headers are always initialized via ContextWithHeaders.

func ContextWithHeaders

func ContextWithHeaders(ctx context.Context, headersSetters ...HeaderSetter) (context.Context, error)

ContextWithHeaders creates a new context with predefined headerPrefixes. Needed when starting from a fresh context, as they will not come with the Header keys needed to send the header to the next service.

func GetASCIIHeaderByName

func GetASCIIHeaderByName(ctx context.Context, name string) (string, error)

GetStringHeaderByName takes the inbound header and returns the data, if it is a string. If no header exists or the header value is not a string, an empty string will be returned.

func GetAnyBinaryHeader

func GetAnyBinaryHeader(ctx context.Context, destination proto.Message) error

GetAnyBinaryHeader will try to find the header by checking all the binary headers, in the following order.

1. GetRootHeader() 2. GetHeader() 3. GetPropagatingHeader()

Note, it is not recommended to to use this method to retrieve headers, as it may induce some ambiguity. For example, XiUUid may have a different meaning in each Type.

func GetAnyBinaryHeaderByName

func GetAnyBinaryHeaderByName(ctx context.Context, destination proto.Message, name string) error

GetAnyBinaryHeaderByName will try to find the header by checking all the binary headers, in the following order.

1. GetRootHeader() 2. GetHeader() 3. GetPropagatingHeader()

Note, it is not recommended to to use this method to retrieve headers, as it may induce some ambiguity. For example, XiUUid may have a different meaning in each Type.

func GetHeader

func GetHeader(ctx context.Context, destination proto.Message) error

GetHeader takes the inbound header and unmarshal the data into the destination message. If no header exists, destination will have all default values.

func GetHeaderByName

func GetHeaderByName(ctx context.Context, destination proto.Message, name string) error

GetHeaderByName takes the inbound header and unmarshal the data into the destination messaging. If no header exists, destination will have all default values.

func GetPropagatingHeader

func GetPropagatingHeader(ctx context.Context, destination proto.Message) error

GetPropagatingHeader takes the propagating header and unmarshal the data into the destination message. If no header exists, destination will have all default values

func GetRootHeader

func GetRootHeader(ctx context.Context, destination proto.Message) error

GetRootHeader takes the root header and unmarshal the data into the destination message. If no header exists, destination will have all default values.

func GetRootHeaderByName

func GetRootHeaderByName(ctx context.Context, destination proto.Message, name string) error

GetRootHeaderByName takes the root header and unmarshal the data into the destination message. If no header exists, destination will have all default values.

func GetStringHeaderByName

func GetStringHeaderByName(ctx context.Context, name string) (string, error)

GetStringHeaderByName takes the inbound header and returns the data, if it is a string. If no header exists or the header value is not a string, an empty string will be returned.

func SetASCIIHeader

func SetASCIIHeader(ctx context.Context, name string, data string) error

SetASCIIHeader sets an ASCII header in the given context.

func SetHeader

func SetHeader(ctx context.Context, data proto.Message) error

SetHeader sets the outbound header in the given context.

func SetHeaderByName

func SetHeaderByName(ctx context.Context, data proto.Message, name string) error

SetHeaderByName sets the outbound header in the given context.

func SetPropagatingHeader

func SetPropagatingHeader(ctx context.Context, data proto.Message) error

SetPropagatingHeader sets the propagating header in the given context.

func StreamClientInterceptor

func StreamClientInterceptor() grpc.StreamClientInterceptor

StreamClientInterceptor sends all the headers in the current context to a server stream

func StreamServerInterceptor

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a grpc.StreamServerInterceptor that takes all the appropriate headerPrefixes from the metadata and puts it into the context of the streamWrapper

func UnaryClientInterceptor

func UnaryClientInterceptor() grpc.UnaryClientInterceptor

UnaryClientInterceptor sends all the headers in the current context to server

func UnaryServerInterceptor

func UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a grpc.UnaryServerInterceptor that takes all the appropriate headerPrefixes from the metadata and puts it into the context

Types

type HeaderKey

type HeaderKey string

HeaderKey is the key to store all the header information in the context

type HeaderSetter

type HeaderSetter struct {
	HeaderSetterFunc headerSetterFunc
	Data             proto.Message
}

HeaderSetter a pair of a headerSetterFunc and the proto header to set. It is meant to be used with ContextWithHeaders to create a new context with all the proper Header information.

func DefaultHeaderSetter

func DefaultHeaderSetter(namedProto proto.Message) HeaderSetter

DefaultHeaderSetter returns a HeaderSetter using the SetHeader and the namedProto passed in as the Data.

func PropagatingHeaderSetter

func PropagatingHeaderSetter(namedProto proto.Message) HeaderSetter

PropagatingHeaderSetter returns a HeaderSetter using SetPropagatingHeader and the namedProto passed in as the Data.

type Headers

type Headers map[string]interface{}

Headers a custom map that takes a string as a key and either a string or []byte as its value

type Type

type Type int

Type represents the header type

const (
	// Outbound headers are only sent on the next service call. They are received as Inbound headers
	// on the recipients side.
	Outbound Type = iota
	// Inbound headers are received from the previous service call, and will not be sent to future service calls
	Inbound
	// Root headers are created from edge layers, and will be passed on to all future service calls
	Root
	// Propagating headers can be created by anyone, and will be passed on to all future service calls
	Propagating
	// ASCII headers are similar to Inbound headers, except the header is pure text and not an encoded protobuf
	ASCII
)

func (Type) String

func (h Type) String() string

Jump to

Keyboard shortcuts

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