oncehttp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package oncehttp is a small client for the once HTTP API.

Index

Constants

View Source
const DefaultMaxResponseBytes int64 = 16 << 20

DefaultMaxResponseBytes is the default cap for successful JSON responses.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to a once HTTP server.

func New

func New(baseURL string, opts ...Option) (*Client, error)

New returns a client for a once HTTP server.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, req CommitRequest) (Record, error)

Commit commits a terminal result for a running key.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, key, attemptToken string, force bool) error

Delete deletes one record through the HTTP repair endpoint.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (Record, error)

Get returns one record.

func (*Client) Reserve

func (c *Client) Reserve(ctx context.Context, req ReserveRequest) (ReserveResponse, error)

Reserve reserves a key or returns the existing record.

type CommitRequest

type CommitRequest struct {
	Key          string `json:"key"`
	AttemptToken string `json:"attempt_token"`
	State        State  `json:"state"`
	ExitCode     int    `json:"exit_code"`
	Stdout       []byte `json:"stdout_b64,omitempty"`
	Stderr       []byte `json:"stderr_b64,omitempty"`
	Error        string `json:"error,omitempty"`
}

CommitRequest commits a terminal result for a running key.

type Error

type Error struct {
	StatusCode int
	Status     string
	Message    string
}

Error is returned for non-2xx HTTP responses.

func (*Error) Error

func (e *Error) Error() string

type Option

type Option func(*Client) error

Option configures a Client.

func WithBearerToken

func WithBearerToken(token string) Option

WithBearerToken configures HTTP bearer authentication.

func WithHTTPClient added in v1.0.0

func WithHTTPClient(client *http.Client) Option

WithHTTPClient configures the underlying HTTP client. The client is copied, and redirects remain disabled so credentials and attempt tokens stay bound to the configured once server.

func WithMaxResponseBytes

func WithMaxResponseBytes(n int64) Option

WithMaxResponseBytes sets the maximum successful JSON response size.

type Record

type Record struct {
	Key        string     `json:"key"`
	State      State      `json:"state"`
	ExitCode   int        `json:"exit_code"`
	Stdout     []byte     `json:"stdout_b64,omitempty"`
	Stderr     []byte     `json:"stderr_b64,omitempty"`
	Error      string     `json:"error,omitempty"`
	Command    []string   `json:"command,omitempty"`
	StartedAt  time.Time  `json:"started_at"`
	FinishedAt *time.Time `json:"finished_at,omitempty"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

Record is the HTTP representation of one once idempotency record.

type ReserveRequest

type ReserveRequest struct {
	Key     string   `json:"key"`
	Command []string `json:"command,omitempty"`
}

ReserveRequest reserves a key or fetches the existing record for that key.

type ReserveResponse

type ReserveResponse struct {
	Fresh        bool   `json:"fresh"`
	AttemptToken string `json:"attempt_token,omitempty"`
	Record       Record `json:"record"`
}

ReserveResponse is returned by Reserve.

type State

type State string

State is the stored state of an idempotency record.

const (
	// Running means a key was reserved but has no terminal result.
	Running State = "running"
	// Succeeded means a terminal success was committed.
	Succeeded State = "succeeded"
	// Failed means a terminal failure was committed.
	Failed State = "failed"
)

Jump to

Keyboard shortcuts

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