Documentation
¶
Overview ¶
Package httpcall records the outbound HTTP calls of an execution and enforces the HTTP call limit.
Two values travel in the execution context. A Limiter, put there by runner.Run, counts every call of the execution against the limit. A Collector, put there by the engine around each top-level node, gathers that node's calls into its result. Loop, poll and module bodies run on the node's context, so their calls count against the same limit and land in the same node result.
Index ¶
- Constants
- func PathTemplate(template string) string
- func Wait(ctx context.Context) error
- func WithCollector(ctx context.Context, collector *Collector) context.Context
- func WithLimiter(ctx context.Context, limiter *Limiter) context.Context
- func WithPacer(ctx context.Context, pacer *Pacer) context.Context
- type Call
- type Collector
- type Limiter
- type Outcome
- type Pacer
- type Target
Constants ¶
const LimitExceededCode = "HTTP_CALL_LIMIT_EXCEEDED"
LimitExceededCode is the error code of the node whose call passed the limit.
Variables ¶
This section is empty.
Functions ¶
func PathTemplate ¶
PathTemplate returns the path of an unresolved URL template, with each {{ expression }} written as {expression}. The scheme and host, or a leading variable that holds them, the query string and the fragment are dropped.
{{baseUrl}}/users/{{ userId }}?expand=true -> /users/{userId}
https://api.example.com/orders/{{id}} -> /orders/{id}
https://api.example.com -> /
func Wait ¶ added in v0.97.0
Wait waits for the next request start, or returns the context error. A cancelled waiter consumes no future slot and is never recorded as a call.
func WithCollector ¶
WithCollector returns ctx carrying collector.
func WithLimiter ¶
WithLimiter returns ctx carrying limiter.
Types ¶
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
Call is a started call. A nil *Call and a call started without a collector record nothing.
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector gathers the calls of one top-level node. It is safe for concurrent use by the parallel nodes of a body.
func CollectorFrom ¶
CollectorFrom returns the collector in ctx, or nil.
func (*Collector) Groups ¶
func (c *Collector) Groups() []spi.HTTPCallGroup
Groups returns the collected calls grouped by node, method, host and path template. Groups are ordered by their first call and calls by start time.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter counts the calls of one execution. It is safe for concurrent use.
func NewLimiter ¶
NewLimiter returns a limiter that refuses the call past limit. A limit of zero or less never refuses.
type Outcome ¶
type Outcome struct {
StatusCode int
TransportError spi.HTTPCallErrorClass
ResponseBytes *int64
}
Outcome is how a call ended. StatusCode is 0 when no response arrived, and TransportError then says why. Leave ResponseBytes nil for a streamed body.