runtime

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package runtime manages request-scoped execution state, step outputs, and context lifecycles for pipeline runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args map[string]any

Args represents evaluated arguments passed to a Go step from an HCL manifest.

func (Args) Bind

func (a Args) Bind(dst any) error

Bind marshals and unmarshals arguments directly into a destination struct.

func (Args) Get

func (a Args) Get[T any](key string) (T, bool)

Get retrieves the argument at key and converts it to type T. Returns (zero, false) if the key is missing, null, or incompatible.

Example:

lat, ok := step.Args.Get[float64]("latitude")
role, ok := step.Args.Get[string]("role")
meta, ok := step.Args.Get[map[string]any]("metadata")

func (Args) GetOr

func (a Args) GetOr[T any](key string, fallback T) T

GetOr is like Get but returns a fallback if key is missing or null.

port := step.Args.GetOr("port", 8080)          // Inferred as int
host := step.Args.GetOr("host", "localhost")   // Inferred as string
priority := step.Args.GetOr("priority", false) // Inferred as bool
ratio := step.Args.GetOr("ratio", 0.95)        // Inferred as float64

func (Args) Has

func (a Args) Has(key string) bool

Has reports whether key exists in the arguments map and is not nil.

func (Args) Slice

func (a Args) Slice[T any](key string) []T

Slice retrieves an array of type T at key, safely coercing dynamic []any slices.

Example:

tags := step.Args.Slice[string]("tags")
ids  := step.Args.Slice[int]("user_ids")

type ExecutionContext

type ExecutionContext struct {
	Request           *RequestState         `json:"request"`
	Steps             map[string]StepResult `json:"steps"`
	TimestampEpoch    int64                 `json:"timestamp_epoch"`
	IngressTime       time.Time             `json:"-"`
	MaxBodySize       int64                 `json:"-"`
	ProblemTypePrefix string                `json:"-"`
	RawRequest        *http.Request         `json:"-"`
	// contains filtered or unexported fields
}

ExecutionContext encapsulates the state, context, and accumulated step outputs for a single request.

func NewExecutionContext

func NewExecutionContext(w http.ResponseWriter, r *http.Request, opts ...ExecutionContextOption) (*ExecutionContext, error)

NewExecutionContext parses the incoming HTTP request, applies size constraints, and initializes pipeline state.

func (*ExecutionContext) Context

func (e *ExecutionContext) Context() context.Context

Context returns the underlying standard library request context.

func (*ExecutionContext) GetStepResult

func (e *ExecutionContext) GetStepResult(stepName string) (StepResult, bool)

GetStepResult retrieves the outputs of a previously executed step.

func (*ExecutionContext) NewStep

func (e *ExecutionContext) NewStep(name string, args Args) *Step

NewStep creates an execution handle for a named step with evaluated arguments.

func (*ExecutionContext) SetStepResult

func (e *ExecutionContext) SetStepResult(stepName string, result StepResult)

SetStepResult stores the exported outputs of a completed step.

func (*ExecutionContext) SnapshotSteps

func (e *ExecutionContext) SnapshotSteps() map[string]StepResult

SnapshotSteps returns a shallow copy of all step outputs recorded up to this point.

func (*ExecutionContext) WithContext

func (e *ExecutionContext) WithContext(ctx context.Context) *ExecutionContext

WithContext returns a shallow copy of ExecutionContext with an updated standard library context.

type ExecutionContextOption

type ExecutionContextOption func(*executionContextConfig)

ExecutionContextOption configures optional behavior when initializing an ExecutionContext.

func WithMaxBodySize added in v0.1.3

func WithMaxBodySize(maxBytes int64) ExecutionContextOption

WithMaxBodySize enforces an upper byte limit on the incoming HTTP request body.

func WithPathParams

func WithPathParams(paramNames []string) ExecutionContextOption

WithPathParams configures the route path parameter names to extract from the request.

func WithProblemTypePrefix added in v0.1.3

func WithProblemTypePrefix(prefix string) ExecutionContextOption

WithProblemTypePrefix sets the base URI prefix used when deriving RFC 9457 problem error types.

type RequestState

type RequestState struct {
	Method  string            `json:"method"`
	Path    map[string]string `json:"path"`
	Query   map[string]string `json:"query"`
	Headers map[string]string `json:"headers"`
	Body    any               `json:"body"`
}

RequestState holds normalized, read-only metadata extracted from an incoming HTTP request.

func (*RequestState) Header

func (r *RequestState) Header(key string) string

Header returns the case-insensitive HTTP request header for key.

func (*RequestState) PathParam

func (r *RequestState) PathParam(key string, fallback ...string) string

PathParam returns the route path parameter for key, or fallback if absent.

func (*RequestState) QueryParam

func (r *RequestState) QueryParam(key string, fallback ...string) string

QueryParam returns the URL query parameter for key, or fallback if absent.

type Step

type Step struct {
	*ExecutionContext
	Name string `json:"name"`
	Args Args   `json:"args"`
}

Step wraps ExecutionContext with step-specific metadata and evaluated arguments for a Go step handler.

func (*Step) Problem

func (s *Step) Problem(status int, detail string) problem.Problem

Problem constructs an RFC 9457 Problem Details error bound to this step's name and request instance.

type StepHandler

type StepHandler func(ctx context.Context, step *Step) (any, error)

StepHandler defines the signature for custom native Go step callbacks.

type StepResult

type StepResult = map[string]any

StepResult represents the exported outputs of a completed pipeline step.

Jump to

Keyboard shortcuts

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