Documentation
¶
Index ¶
- Constants
- func CloneContext(parent context.Context) (cloned context.Context)
- func ContextWithClonedFrameOf(parent context.Context, x any) (ctx context.Context)
- func ContextWithFrame(parent context.Context) (ctx context.Context)
- func ContextWithFrameOf(parent context.Context, x any) (ctx context.Context)
- type Frame
- func (f Frame) Baggage(name string) (value string)
- func (f Frame) CallDepth() int
- func (f Frame) ClockShift() time.Duration
- func (f Frame) Fragment() (index int, max int)
- func (f Frame) FromHost() string
- func (f Frame) FromID() string
- func (f Frame) FromVersion() int
- func (f Frame) Get(name string) string
- func (f Frame) Header() http.Header
- func (f Frame) IfActor(boolExp string) (ok bool, err error)
- func (f Frame) IncrementClockShift(increment time.Duration)
- func (f Frame) IsNil() bool
- func (f Frame) Languages() []string
- func (f Frame) Locality() string
- func (f Frame) MessageID() string
- func (f Frame) OpCode() string
- func (f Frame) ParseActor(obj any) (ok bool, err error)
- func (f Frame) Queue() string
- func (f Frame) Set(name string, value string)
- func (f Frame) SetActor(actor any) error
- func (f Frame) SetBaggage(name string, value string)
- func (f Frame) SetCallDepth(depth int)
- func (f Frame) SetClockShift(shift time.Duration)
- func (f Frame) SetFragment(index int, max int)
- func (f Frame) SetFromHost(host string)
- func (f Frame) SetFromID(id string)
- func (f Frame) SetFromVersion(version int)
- func (f Frame) SetLanguages(language ...string)
- func (f Frame) SetLocality(locality string)
- func (f Frame) SetMessageID(id string)
- func (f Frame) SetOpCode(op string)
- func (f Frame) SetQueue(queue string)
- func (f Frame) SetTimeBudget(budget time.Duration)
- func (f Frame) TimeBudget() time.Duration
- func (f Frame) XForwardedBaseURL() string
- func (f Frame) XForwardedFullURL() string
Constants ¶
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" HeaderActor = HeaderPrefix + "Actor" OpCodeError = "Err" OpCodeAck = "Ack" OpCodeRequest = "Req" OpCodeResponse = "Res" )
Variables ¶
This section is empty.
Functions ¶
func CloneContext ¶
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. In either case, the returned context is guaranteed to have a frame. Manipulating the frame of the cloned context does not impact the parent's.
func ContextWithClonedFrameOf ¶ added in v1.14.0
ContextWithClonedFrameOf returns a copy of the parent context, setting on it a clone of the frame obtained from x. Manipulating the frame of the returned context does not impact the parent's.
func ContextWithFrame ¶
ContextWithFrame returns either the parent, or a copy of the parent with a new frame. In either case, the returned context is guaranteed to have a 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 ¶
Of creates a new frame wrapping the headers of the HTTP request, response, response writer, header, or context.
func (Frame) Baggage ¶
Baggage is an arbitrary name=value pair that is passed through to downstream microservices.
func (Frame) CallDepth ¶
CallDepth is the depth of the call stack beginning at the original request.
func (Frame) ClockShift ¶
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 ¶
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 ¶
FromHost is the hostname of the microservice that made the request or response.
func (Frame) FromID ¶
FromID is the unique ID of the instance of the microservice that made the request or response.
func (Frame) FromVersion ¶
FromVersion is the version number of the microservice that made the request or response.
func (Frame) IfActor ¶ added in v1.13.1
IfActor evaluates the boolean expression against the properties of the actor associated with the frame. The =~ and !~ operators evaluate the left operand against a regexp. String constants, including regexp patterns, must be quoted using single quotes, double quotes or backticks.
For example, "iss=='my_issuer' && (roles.admin || roles.manager) && foo!='baz' && level>=5 && region=~'US'" evaluates to true for the actor {"iss":"my_issuer","sub":"harry@hogwarts.edu","roles":["admin"],"foo":"bar","level":5,"region":"AMER US"}.
func (Frame) IncrementClockShift ¶ added in v1.13.1
IncrementClockShift adds to the clock offset in the frame. A clock shift enables time-coordinated testing across microservices. A positive offset shifts the clock into the future. A negative offset shifts the clock into the past.
func (Frame) IsNil ¶ added in v1.13.1
IsNil indicates if the frame's internal header representation is nil.
func (Frame) Languages ¶
Languages parses the Accept-Language header and returns the listed languages in order of their q value.
func (Frame) Locality ¶
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) ParseActor ¶ added in v1.13.1
ParseActor parses the actor associated with the frame into the provided object. The OK flag indicates whether or not an actor is associated with the frame.
func (Frame) Queue ¶
Queue indicates the queue of the subscription that handled the request. It is used by the client to optimize multicast requests.
func (Frame) SetBaggage ¶
SetBaggage sets an arbitrary name=value pair that is passed through to downstream microservices.
func (Frame) SetCallDepth ¶
SetCallDepth sets the depth of the call stack beginning at the original request.
func (Frame) SetClockShift ¶
SetClockShift sets the clock shift in the frame. A clock shift enables time-coordinated testing across microservices. A positive offset shifts the clock into the future. A negative offset shifts the clock into the past.
func (Frame) SetFragment ¶
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 ¶
SetFromHost sets the hostname of the microservice that is making the request or response.
func (Frame) SetFromID ¶
SetFromID sets the unique ID of the instance of the microservice that is making the request or response.
func (Frame) SetFromVersion ¶
SetFromVersion sets the version number of the microservice that is making the request or response.
func (Frame) SetLanguages ¶
SetLanguages sets the Accept-Language header with the list of languages.
func (Frame) SetLocality ¶
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 ¶
SetMessageID sets the unique ID given to each HTTP message or response.
func (Frame) SetQueue ¶
SetQueue sets the queue of the subscription that handled the request. It is used by the client to optimize multicast requests.
func (Frame) SetTimeBudget ¶
SetTimeBudget budgets a duration for the request to complete. A value of 0 indicates no time budget.
func (Frame) TimeBudget ¶
TimeBudget is the duration budgeted for the request to complete. A value of 0 indicates no time budget.
func (Frame) XForwardedBaseURL ¶
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 ¶
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.