Help us shape the future of Go! Take the 2026 Go Developer Survey

invoke

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package invoke is the chain every call to a function's worker runs (ADR-0302): invokePlugins, steps compiled into funcd, at three points of a call. Admit runs before anything about the Function is read, Before before the worker is called or woken, and After once it answered, before the caller sees the answer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdmitPlugin

type AdmitPlugin interface {
	Plugin
	Admit(ctx context.Context, c *Call) *Refusal
}

AdmitPlugin runs before anything about the Function is read.

type AfterPlugin

type AfterPlugin interface {
	Plugin
	After(ctx context.Context, c *Call, a *Answer) *Refusal
}

AfterPlugin runs once the worker answered, before the caller sees the answer.

type Answer

type Answer struct {
	Status int
	Header http.Header
	// contains filtered or unexported fields
}

Answer is the worker's answer at the After point.

func NewAnswer

func NewAnswer(res *http.Response) *Answer

NewAnswer wraps res. Body puts what it read back on res.Body, so the caller still gets the whole body.

func (*Answer) Body

func (a *Answer) Body(limit int64) ([]byte, error)

Body reads the answer's body, up to limit bytes; a longer body returns a fault.PayloadTooLarge. An answer whose body no plugin reads is never buffered, so it streams. A later call with a larger limit reads on.

type BeforePlugin

type BeforePlugin interface {
	Plugin
	Before(ctx context.Context, c *Call) *Refusal
}

BeforePlugin runs before the worker is called or woken.

type Call

type Call struct {
	Caller    Caller
	Target    activator.FunctionRef // namespace, name and a step's revision pin (ADR-0190)
	Stance    v1.AuthMode           // External: the stance the route resolved (ADR-0113); "" otherwise
	Remainder string                // External and Function: the function-relative path
	Received  time.Time             // External: when the listener received the call (ADR-0151)
	Request   *http.Request         // what the worker gets; a Before plugin may replace it
	Function  *v1.Function          // set by the data plane before Before; nil at Admit and on the other paths
}

Call is one call to a function's worker.

type Caller

type Caller int

Caller is who makes a call.

const (
	External     Caller = iota + 1 // the data-plane listener, by name or through a Route
	FnToFn                         // a Function's own call (ADR-0064)
	WorkflowStep                   // a workflow step (ADR-0094)
	SensorAction                   // a Sensor's function action (ADR-0108)
	AppHook                        // an App's lifecycle hook (ADR-0214)
)

func (Caller) String

func (c Caller) String() string

String names the caller in logs and test failures.

type Chain

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

Chain runs its plugins in order. It is safe for concurrent use; a nil Chain runs nothing.

func NewChain

func NewChain(plugins ...Plugin) *Chain

NewChain returns the chain of plugins, in their order.

func (*Chain) Admit

func (ch *Chain) Admit(ctx context.Context, c *Call) *Refusal

Admit runs each applicable AdmitPlugin; the first refusal ends the call.

func (*Chain) After

func (ch *Chain) After(ctx context.Context, c *Call, a *Answer) *Refusal

After runs each applicable AfterPlugin; the first refusal replaces the worker's answer.

func (*Chain) Before

func (ch *Chain) Before(ctx context.Context, c *Call) *Refusal

Before runs each applicable BeforePlugin; the first refusal ends the call before its worker.

type Plugin

type Plugin interface {
	Name() string
	Applies(c *Call) bool
}

Plugin is an invokePlugin; it also implements one or more of AdmitPlugin, BeforePlugin and AfterPlugin. Applies reads the call's facts, never its body.

type Refusal

type Refusal struct {
	Err    error
	Header http.Header // set before the answer, e.g. Retry-After
	Status int
	Body   []byte
}

Refusal ends a call before its worker, or replaces the worker's answer: an RFC 9457 problem from Err, or, when Status is set, that status with Body, for an answer an ADR fixes in another shape (ADR-0058's contract answers).

func (*Refusal) Error

func (r *Refusal) Error() string

Error is Err's text, else the status and the body, which a client path keeps in a step's or an Invocation's error.

func (*Refusal) StatusCode

func (r *Refusal) StatusCode() int

StatusCode is the status the refusal answers with.

func (*Refusal) Unwrap

func (r *Refusal) Unwrap() error

Unwrap returns Err, so fault.KindOf reads a problem refusal's kind.

func (*Refusal) WriteAnswer

func (r *Refusal) WriteAnswer(w http.ResponseWriter)

WriteAnswer writes the refusal to w: its headers, then its problem, or its status and body. It sets no Content-Type of its own, so a refusal with a body carries one in Header.

Jump to

Keyboard shortcuts

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