frame

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderPrefix        = "Microbus-"
	HeaderBaggagePrefix = HeaderPrefix + "Baggage-"
	HeaderMsgId         = HeaderPrefix + "Msg-Id"
	HeaderFromHost      = HeaderPrefix + "From-Host"
	HeaderFromId        = HeaderPrefix + "From-Id"
	HeaderFromVersion   = HeaderPrefix + "From-Version"
	HeaderTimeBudget    = HeaderPrefix + "Time-Budget"
	HeaderCallDepth     = HeaderPrefix + "Call-Depth"
	HeaderOpCode        = HeaderPrefix + "Op-Code"
	HeaderQueue         = HeaderPrefix + "Queue"
	HeaderFragment      = HeaderPrefix + "Fragment"
	HeaderClockShift    = HeaderPrefix + "Clock-Shift"
	HeaderLocality      = HeaderPrefix + "Locality"

	OpCodeError    = "Err"
	OpCodeAck      = "Ack"
	OpCodeRequest  = "Req"
	OpCodeResponse = "Res"
)

Variables

This section is empty.

Functions

func CloneContext

func CloneContext(parent context.Context) (cloned context.Context)

CloneContext returns a new context with a copy of the frame of the parent context, or a new frame if it does not have one. Manipulating the frame of the cloned context does not impact the parent's.

func ContextWithFrame

func ContextWithFrame(parent context.Context) (ctx context.Context)

ContextWithFrame adds a new empty frame to the context. If the parent includes a frame, it will be superseded by the given frame.

func ContextWithFrameOf

func ContextWithFrameOf(parent context.Context, x any) (ctx context.Context)

ContextWithFrameOf returns a new context derived from the parent, referencing the frame of x. If the parent includes a frame, it will be superseded by the given frame. Manipulating the frame of the new context impacts the original frame.

Types

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

Frame is a utility class that helps with manipulating the control headers.

func Of

func Of(x any) Frame

Of creates a new frame wrapping the headers of the HTTP request, response, response writer, header, or context.

func (Frame) Baggage

func (f Frame) Baggage(name string) string

Baggage is an arbitrary header that is passed through to downstream microservices.

func (Frame) CallDepth

func (f Frame) CallDepth() int

CallDepth is the depth of the call stack beginning at the original request.

func (Frame) ClockShift

func (f Frame) ClockShift() time.Duration

ClockShift returns the time offset set in the frame. Time offsets are used during testing to offset the clock of a transaction. A positive offset moves the clock into the future. A negative offset moves the clock into the past.

func (Frame) Fragment

func (f Frame) Fragment() (index int, max int)

Fragment returns the index of the fragment of large messages out of the total number of fragments. Fragments are indexed starting at 1.

func (Frame) FromHost

func (f Frame) FromHost() string

FromHost is the hostname of the microservice that made the request or response.

func (Frame) FromID

func (f Frame) FromID() string

FromID is the unique ID of the instance of the microservice that made the request or response.

func (Frame) FromVersion

func (f Frame) FromVersion() int

FromVersion is the version number of the microservice that made the request or response.

func (Frame) Get

func (f Frame) Get(name string) string

Get returns an arbitrary header.

func (Frame) Header

func (f Frame) Header() http.Header

Header returns the underlying HTTP header backing the frame.

func (Frame) Languages

func (f Frame) Languages() []string

Languages parses the Accept-Language header and returns the listed languages in order of their q value.

func (Frame) Locality

func (f Frame) Locality() string

Locality indicates the geographic locality of the microservice that handled the request. It is used by the client to optimize routing of unicast requests.

func (Frame) MessageID

func (f Frame) MessageID() string

MessageID is the unique ID given to each HTTP message and its response.

func (Frame) OpCode

func (f Frame) OpCode() string

OpCode indicates the type of the control message.

func (Frame) Queue

func (f Frame) Queue() string

Queue indicates the queue of the subscription that handled the request. It is used by the client to optimize multicast requests.

func (Frame) Set

func (f Frame) Set(name string, value string)

Set sets the value of an arbitrary header.

func (Frame) SetBaggage

func (f Frame) SetBaggage(name string, value string)

SetBaggage sets an arbitrary header that is passed through to downstream microservices.

func (Frame) SetCallDepth

func (f Frame) SetCallDepth(depth int)

SetCallDepth sets the depth of the call stack beginning at the original request.

func (Frame) SetClockShift

func (f Frame) SetClockShift(offset time.Duration)

SetClockShift sets the time offset in the frame. Time offsets are used during testing to offset the clock of a transaction. A positive offset moves the clock into the future. A negative offset moves the clock into the past.

func (Frame) SetFragment

func (f Frame) SetFragment(index int, max int)

Fragment sets the index of the fragment of large messages out of the total number of fragments. Fragments are indexed starting at 1.

func (Frame) SetFromHost

func (f Frame) SetFromHost(host string)

SetFromHost sets the hostname of the microservice that is making the request or response.

func (Frame) SetFromID

func (f Frame) SetFromID(id string)

SetFromID sets the unique ID of the instance of the microservice that is making the request or response.

func (Frame) SetFromVersion

func (f Frame) SetFromVersion(version int)

SetFromVersion sets the version number of the microservice that is making the request or response.

func (Frame) SetLanguages

func (f Frame) SetLanguages(language ...string)

SetLanguages sets the Accept-Language header with the list of languages.

func (Frame) SetLocality

func (f Frame) SetLocality(locality string)

SetLocality sets the geographic locality of the microservice that handled the request. It is used by the client to optimize routing of unicast requests.

func (Frame) SetMessageID

func (f Frame) SetMessageID(id string)

SetMessageID sets the unique ID given to each HTTP message or response.

func (Frame) SetOpCode

func (f Frame) SetOpCode(op string)

SetOpCode sets the type of the control message.

func (Frame) SetQueue

func (f Frame) SetQueue(queue string)

SetQueue sets the queue of the subscription that handled the request. It is used by the client to optimize multicast requests.

func (Frame) SetTimeBudget

func (f Frame) SetTimeBudget(budget time.Duration)

SetTimeBudget budgets a duration for the request to complete. A value of 0 indicates no time budget.

func (Frame) TimeBudget

func (f Frame) TimeBudget() time.Duration

TimeBudget is the duration budgeted for the request to complete. A value of 0 indicates no time budget.

func (Frame) XForwardedBaseURL

func (f Frame) XForwardedBaseURL() string

XForwardedBaseURL returns the amalgamated headers X-Forwarded-Proto, -Host and -Prefix, without a trailing slash. The empty string is returned if the headers are not present.

func (Frame) XForwardedFullURL

func (f Frame) XForwardedFullURL() string

XForwardedFullURL returns the amalgamated headers X-Forwarded-Proto, -Host, -Prefix and -Path, without a trailing slash. The empty string is returned if the headers are not present.

Jump to

Keyboard shortcuts

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