engine

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine runs CCHP operations through embedded Restish v2.

cchp owns the command tree, policy and output contract; Restish builds and sends the HTTP request from the pinned engine spec. The two meet only through Restish's supported embedding interfaces: a branded CLI with bundled config, a custom auth handler, a JSON content type that sends bodies byte for byte, a capture formatter, Restish's raw body output for downloads, and the process HTTP transport, which guards every request and records each response head.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commands

func Commands(stateDir string, specGzip []byte) ([]string, string, error)

Commands lists the operation commands Restish builds from the engine spec, with any warnings it printed. cchp-gen uses it to run the whole spec through the engine and report operations it cannot build as unsupported.

func DecodeJSON

func DecodeJSON(data []byte) (any, error)

DecodeJSON decodes one JSON document keeping numbers as json.Number.

func SameOrigin

func SameOrigin(a, b *url.URL) bool

SameOrigin compares scheme, host and effective port.

Types

type Engine

type Engine struct {
	// BaseURL is the bound server, for example https://hub.example.com.
	BaseURL string
	// Token is the management token; empty for public operations and dry runs.
	Token string
	// StateDir holds the materialised engine spec and Restish's private config and cache.
	StateDir string
	// SpecGzip is the embedded engine spec.
	SpecGzip []byte
	// UserAgent is sent with every request.
	UserAgent string
}

Engine executes operations against one bound server.

func (*Engine) Do

func (e *Engine) Do(ctx context.Context, req Request) (*Result, error)

Do sends the request and returns the response.

func (*Engine) Plan

func (e *Engine) Plan(ctx context.Context, req Request) (*PlannedRequest, error)

Plan returns the request a dry run would send.

type Event

type Event struct {
	Payload any
}

Event is one server-sent event as Restish decoded it.

type Flag

type Flag struct {
	Name  string
	Value string
}

Flag is one parameter flag value.

type NotSentError

type NotSentError struct{ Err error }

NotSentError reports a failure before any byte reached the server.

func (*NotSentError) Error

func (e *NotSentError) Error() string

func (*NotSentError) Unwrap

func (e *NotSentError) Unwrap() error

type PlannedRequest

type PlannedRequest struct {
	Method string      `json:"method"`
	URL    string      `json:"url"`
	Header http.Header `json:"headers"`
	Body   []byte      `json:"-"`
}

PlannedRequest is what a dry run would have sent.

type Request

type Request struct {
	Op *catalog.Operation
	// PathArgs holds path parameter values in path template order.
	PathArgs []string
	// Flags holds non-path parameters as flag/value pairs; array values repeat.
	Flags []Flag
	// Headers are extra "Name: value" request headers managed by cchp.
	Headers []string
	// JSONBody is sent byte for byte as the application/json body.
	JSONBody []byte
	// BinaryFile is sent as the raw request body.
	BinaryFile string
	// FormFiles maps multipart field names to local file paths.
	FormFiles map[string]string
	// Retry allows Restish's automatic retry of transient failures (reads only).
	Retry bool
	// HeaderTimeout bounds the wait for response headers.
	HeaderTimeout time.Duration
	// MaxBodyMiB raises the response size limit for downloads.
	MaxBodyMiB int
	// MaxEvents stops a stream after this many events.
	MaxEvents int
	// OnEvent receives stream events; returning an error stops the stream.
	OnEvent func(Event) error
	// RawBody returns the response body byte for byte whatever its Content-Type,
	// server-sent events and NDJSON included; downloads use it.
	RawBody bool
	// DryRun builds the request without sending it.
	DryRun bool
}

Request is one operation call.

type Result

type Result struct {
	Status      int
	Header      http.Header
	Raw         []byte
	Body        any
	Diagnostics string
}

Result is the final HTTP response.

type UnknownOutcomeError

type UnknownOutcomeError struct{ Err error }

UnknownOutcomeError reports a failure after the request may have reached the server.

func (*UnknownOutcomeError) Error

func (e *UnknownOutcomeError) Error() string

func (*UnknownOutcomeError) Unwrap

func (e *UnknownOutcomeError) Unwrap() error

Jump to

Keyboard shortcuts

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