hosted

package
v0.2.37 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package hosted is the one HTTP client the CLI's hosted-service commands (deploy, functions, static, automation) share: the URL check, the bearer header, the error envelope and retries.

Index

Constants

View Source
const DefaultURL = "https://api.altengine.net"

DefaultURL is the hosted service's API origin.

Variables

View Source
var (
	MaxAttempts = 4
	BaseBackoff = 500 * time.Millisecond
	Sleep       = time.Sleep
)

Retries: attempts in all, the first backoff (doubled each time), and the sleep between them (replaced in tests).

Functions

func Backoff

func Backoff(attempt int, retryAfter string) time.Duration

Backoff is the wait before attempt+1: BaseBackoff doubled per attempt, or the server's Retry-After in seconds, capped at 30s.

func CheckURL

func CheckURL(raw string) error

CheckURL refuses a base URL the API key must not be sent to: anything but https, except plain http to this machine (an emulator or a local proxy).

func Idempotent

func Idempotent(method string) bool

Idempotent reports whether a request with this method may be repeated after an ambiguous failure. A POST may deploy twice, so it is not.

func IsLoopback

func IsLoopback(host string) bool

IsLoopback reports whether host names this machine.

func NeverSent

func NeverSent(err error) bool

NeverSent reports whether a transport error happened before the request reached the server (no connection, no address), which makes a retry safe whatever the method.

func Retryable

func Retryable(status int, idempotent bool) bool

Retryable reports whether an answer is worth another attempt. 429 and 503 turn a request away before it is acted on, so any method retries them; 502 and 504 may come after it was acted on, so only a request that is safe to repeat does.

func Seg

func Seg(s string) string

Seg escapes one path segment. Names come from flags and arguments, and a `/` or `?` in one must not address a different route.

func Short

func Short(s string, n int) string

Short returns at most n bytes of an id or hash for display; a shorter one is returned whole rather than panicking.

Types

type Client

type Client struct {
	BaseURL string
	APIKey  string
	// Timeout per request. Generous by default: a large bundle on a slow link is a legitimately
	// slow request, and a timeout leaves someone unsure whether it landed.
	Timeout time.Duration
}

Client calls the hosted API with an org API key.

func (Client) Do

func (c Client) Do(method, path string, body any, out any) error

Do sends one JSON request and decodes the JSON answer into out (when non-nil). A failure the service cannot have acted on, or one that is safe to repeat, is retried with backoff.

type Error

type Error struct {
	Status  int
	Code    string
	Message string
}

Error is the hosted service's error envelope.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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