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

wfinterp

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package wfinterp is an interpreter for the Google Cloud Workflows language: YAML or JSON workflow sources, ${...} expressions and the standard library. It performs no I/O of its own; time, HTTP, logging, callbacks and connectors come from a Host.

Index

Constants

View Source
const (
	TagTypeError          = "TypeError"
	TagValueError         = "ValueError"
	TagKeyError           = "KeyError"
	TagIndexError         = "IndexError"
	TagZeroDivisionError  = "ZeroDivisionError"
	TagArithmeticError    = "ArithmeticError"
	TagHTTPError          = "HttpError"
	TagConnectionError    = "ConnectionError"
	TagConnectionFailed   = "ConnectionFailedError"
	TagTimeoutError       = "TimeoutError"
	TagRecursionError     = "RecursionError"
	TagResourceLimitError = "ResourceLimitError"
	TagResponseTypeError  = "ResponseTypeError"
	TagOperationError     = "OperationError"
	TagUnhandledBranch    = "UnhandledBranchError"
	TagRuntimeError       = "RuntimeError"
	TagAuthError          = "AuthError"
	TagSystemError        = "SystemError"
)

Error tags used by the runtime, as listed in the Workflows error reference.

Variables

This section is empty.

Functions

func ParseJSON

func ParseJSON(raw []byte) (any, error)

ParseJSON decodes JSON into workflow values: integers become int64, other numbers float64.

func ToJSON

func ToJSON(v any) ([]byte, error)

ToJSON encodes a workflow value as JSON; bytes become base64 strings.

Types

type Clock

type Clock interface {
	Now() time.Time
	Sleep(ctx context.Context, d time.Duration) error
}

Clock supplies time to a running workflow; tests inject a fake.

type Engine

type Engine struct {

	// KnownConnector reports whether a googleapis.* name can be called; nil accepts every name.
	KnownConnector func(name string) bool
	// contains filtered or unexported fields
}

Engine holds the function library; it is safe for concurrent use.

func NewEngine

func NewEngine() *Engine

NewEngine returns an Engine with the full standard library.

func (*Engine) Compile

func (e *Engine) Compile(src string) (*Program, error)

Compile parses and validates workflow source (YAML or JSON).

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, p *Program, arg any, host *Host) (any, error)

Run executes the main subworkflow with arg as its argument and returns the workflow result.

type Error

type Error struct {
	Value any
	Stack []Frame
	// contains filtered or unexported fields
}

Error is a workflow error: the value a raise produced or a runtime error map.

func NewError

func NewError(msg string, tags ...string) *Error

NewError builds a catchable error map with the given message and tags, for hosts such as connectors.

func NewHTTPError

func NewHTTPError(code int, headers map[string][]string, body any, msg string) *Error

NewHTTPError builds the error a failed HTTP call raises.

func (*Error) Cancelled

func (e *Error) Cancelled() bool

Cancelled reports whether the error is the execution being cancelled rather than a catchable error.

func (*Error) Context

func (e *Error) Context() string

Context renders the position the way Execution.Error.Context shows it.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Payload

func (e *Error) Payload() string

Payload is the error value as JSON.

type Expr

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

Expr is a parsed ${...} expression.

func ParseExpr

func ParseExpr(src string) (*Expr, error)

ParseExpr parses expression source (without the ${ } wrapper).

func (*Expr) Source

func (e *Expr) Source() string

Source returns the expression text without the ${ } wrapper.

type Frame

type Frame struct {
	Routine string
	Step    string
	Line    int
}

Frame is one position in a workflow: a step of a routine.

type FuncRef

type FuncRef struct{ Name string }

FuncRef is a reference to a named function or subworkflow, as produced by ${http.default_retry_predicate}.

type Host

type Host struct {
	Clock Clock
	HTTP  *http.Client
	// Env resolves sys.get_env names.
	Env func(name string) (string, bool)
	// Log receives sys.log output.
	Log func(LogEntry)
	// Token returns a bearer token for http auth (kind is "OIDC" or "OAuth2").
	Token func(kind, audience, scope, target string) string
	// Connector runs a googleapis.* call; handled is false for an unknown connector.
	Connector func(ctx context.Context, name string, args map[string]any) (result any, handled bool, err error)
	// CreateCallback returns the URL callers POST to in order to resume events.await_callback.
	CreateCallback func(ctx context.Context, method string) (url string, err error)
	// AwaitCallback blocks until the callback at url is called or ctx ends.
	AwaitCallback func(ctx context.Context, url string) (map[string]any, error)
	// Progress is told which steps are executing each time they change.
	Progress func([]Frame)
}

Host connects a running workflow to its surroundings. Every field is optional.

type LogEntry

type LogEntry struct {
	JSON     map[string]any
	Severity string
	Text     string
}

LogEntry is one sys.log call.

type Program

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

Program is a validated workflow.

type RealClock

type RealClock struct{}

RealClock is the wall clock.

func (RealClock) Now

func (RealClock) Now() time.Time

Now returns the current time.

func (RealClock) Sleep

func (RealClock) Sleep(ctx context.Context, d time.Duration) error

Sleep waits for d or until ctx is done.

type SyntaxError

type SyntaxError struct {
	Routine string
	Step    string
	Msg     string
	Line    int
}

SyntaxError is a workflow that fails validation at deploy time.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Jump to

Keyboard shortcuts

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