client

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package client builds an authenticated Hostim API client from resolved config and maps API error responses (including 429 rate limiting) into Go errors.

Index

Constants

This section is empty.

Variables

View Source
var ErrBuildFailed = errors.New("build failed")

ErrBuildFailed is returned by PollBuild when the build reaches "failed".

View Source
var ErrDeployFailed = errors.New("deploy failed")

ErrDeployFailed is returned by PollBuild when a build-less (docker image) deploy cannot become healthy, e.g. the image can't be pulled.

Functions

func Check

func Check(status int, body []byte) error

Check returns an *APIError if the response status is >= 400, else nil. Generated response structs expose StatusCode() and a Body []byte field, so callers use client.Check(resp.StatusCode(), resp.Body).

func New

New returns a ClientWithResponses that injects the Bearer token and transparently retries on 429 responses, honouring Retry-After.

func NewAnonymous added in v0.1.20

func NewAnonymous(apiURL string) (*api.ClientWithResponses, error)

NewAnonymous returns a client for the endpoints that take no token (the device-login flow), with the same 429 retry behaviour as New. Without it a single rate-limited poll would end a login that is otherwise fine.

Types

type APIError

type APIError struct {
	Status  int
	Code    string // GenericMessage.error, when present
	Message string // GenericMessage.message, when present
}

APIError is a structured error built from a non-2xx API response.

func (*APIError) Error

func (e *APIError) Error() string

type BuildResult

type BuildResult struct {
	BuildStatus   api.AppStatusBuildStatus
	RuntimeStatus api.AppStatusRuntimeStatus
	Status        *api.AppStatus
}

BuildResult is the terminal outcome of a deploy poll.

func PollBuild

func PollBuild(
	ctx context.Context,
	c *api.ClientWithResponses,
	project, app string,
	interval time.Duration,
	expectBuild bool,
	onTick func(*api.AppStatus),
) (BuildResult, error)

PollBuild polls an app's status until it reaches a terminal state or the context is cancelled. onTick, if non-nil, is called with each observed status so callers can render progress.

expectBuild selects what "terminal" means:

  • true (git source): wait for buildStatus to reach succeeded/failed. A git deploy always runs a build, so the build outcome is the meaningful signal.
  • false (docker image source): there is no build phase, so buildStatus stays empty and the app goes straight to running. Wait for runtimeStatus instead: running is success, imagePullBackoff is a definitive failure. Transient states (pending/crashing) keep polling until running or timeout.

It returns ErrBuildFailed / ErrDeployFailed (wrapped) on failure so callers can exit non-zero.

Jump to

Keyboard shortcuts

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