exec

package
v0.2.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: 16 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 exec builds HTTP requests from cases and sends them (FR-HTTP).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base

func Base(baseURL, serverURL, specBasePath string) (base, warning string, err error)

Base returns the base URL for requests (FR-HTTP-06).

With a configured BaseURL it replaces the spec's servers entirely; a warning is returned if the servers' base path is missing from it. With an in-process handler (serverURL set, baseURL empty) the servers' base path is appended, because the application is expected to serve its routes there.

func IsWrite

func IsWrite(method string) bool

IsWrite reports whether a method changes state (NFR-07).

func WaitReady

func WaitReady(ctx context.Context, client *http.Client, base, healthPath string, limit time.Duration) error

WaitReady waits until the API answers (FR-HTTP-04). Without healthPath any HTTP response on "/" counts; with healthPath a 2xx is required. Only connection errors and non-2xx health responses are retried.

func WritesAllowed

func WritesAllowed(base string, allowed []string) bool

WritesAllowed reports whether writing requests may go to base (NFR-07): localhost, loopback addresses and hosts in allowed are permitted.

Types

type Auth

type Auth struct {
	// Placements is empty if the operation needs no token (FR-AUTH-04).
	Placements []Placement
	// Unsupported explains why no requirement can be fulfilled.
	Unsupported string
}

Auth is the resolved authentication of an operation.

func ResolveAuth

func ResolveAuth(reqs openapi3.SecurityRequirements, schemes openapi3.SecuritySchemes) Auth

ResolveAuth picks the first security requirement whose schemes are all supported (FR-AUTH-01, FR-AUTH-05). An empty requirement list or an empty requirement means no authentication.

func (Auth) Needed

func (a Auth) Needed() bool

Needed reports whether a token is sent.

type Input

type Input struct {
	Base    string // base URL without trailing slash
	Params  params.Inputs
	Auth    Auth
	Token   string // used if Auth.Needed()
	Headers map[string]string
}

Input is everything Prepare needs besides the case.

type NotBuildableError

type NotBuildableError struct{ Reason string }

NotBuildableError reports that a case cannot be sent (FR-CASE-06).

func (*NotBuildableError) Error

func (e *NotBuildableError) Error() string

type Placement

type Placement struct {
	In   string // "header", "query" or "cookie"
	Name string // header, parameter or cookie name
	// Bearer is set for "Authorization: Bearer <token>".
	Bearer bool
}

Placement is where a token goes in a request.

func AllPlacements

func AllPlacements(schemes openapi3.SecuritySchemes) []Placement

AllPlacements lists every placement defined by the spec's schemes, so that redaction knows all header, query and cookie names carrying tokens.

type Prepared

type Prepared struct {
	Method string
	URL    string // absolute URL
	Target string // path and query, relative to the base URL, for display
	Header http.Header
	Body   []byte
	Auth   Auth // where the token went; used to build curl commands
}

Prepared is a request ready to be sent.

func Prepare

func Prepare(c *cases.Case, in Input) (*Prepared, error)

Prepare builds the request for c. It returns a *NotBuildableError if a required parameter has no value.

func (*Prepared) Request

func (p *Prepared) Request(ctx context.Context) (*http.Request, error)

Request creates the HTTP request for p. ctx should carry the request timeout.

type Response

type Response struct {
	Status   int
	Header   http.Header
	Body     []byte
	Duration time.Duration
}

Response is what the API answered.

func Do

func Do(client *http.Client, req *http.Request, timeout time.Duration) (*Response, error)

Do sends req and reads the response. The timeout must already be part of the request context (FR-HTTP-02); it is only used for the error message. Requests are never retried (FR-HTTP-03).

func Send

func Send(ctx context.Context, client *http.Client, p *Prepared, timeout time.Duration) (*Response, error)

Send sends p with a timeout that only affects this request.

Jump to

Keyboard shortcuts

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