httpcall

package
v0.76.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 10 Imported by: 0

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

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

func PathTemplate(template string) string

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 WithCollector

func WithCollector(ctx context.Context, collector *Collector) context.Context

WithCollector returns ctx carrying collector.

func WithLimiter

func WithLimiter(ctx context.Context, limiter *Limiter) context.Context

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.

func Start

func Start(ctx context.Context, target Target) (*Call, error)

Start reserves the next call of the execution in ctx. Past the limit it returns a user error with LimitExceededCode, and the node must not send the request.

func (*Call) Finish

func (c *Call) Finish(outcome Outcome)

Finish records the call in the node's collector.

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

func CollectorFrom(ctx context.Context) *Collector

CollectorFrom returns the collector in ctx, or nil.

func NewCollector

func NewCollector() *Collector

NewCollector returns an empty collector.

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

func NewLimiter(limit int) *Limiter

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.

type Target

type Target struct {
	NodeID string
	Method string
	// URL is the resolved URL the request is sent to.
	URL string
	// URLTemplate is the node's URL before template resolution.
	URLTemplate string
}

Target names the call a node is about to send.

Jump to

Keyboard shortcuts

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