{"modulePath":"github.com/hostimdev/cli","version":"v0.1.58","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package client\n\nPackage client builds an authenticated Hostim API client from resolved config and maps API error responses (including 429 rate limiting) into Go errors.\n\n## Constants\n\n```go\nconst MaxUploadSize int64 = 500 \u003c\u003c 20\n```\nMaxUploadSize is the largest source archive the API accepts, after gzip.\n\n```go\nconst ProjectIDPrefix = \"hpr-\"\n```\nProjectIDPrefix is the prefix of the system-generated project identifiers used as the {projectName} path parameter by the API. Friendly project names are resolved to an ID before nested calls.\n\n## Variables\n\n```go\nvar ErrBuildFailed = errors.New(\"build failed\")\n```\nErrBuildFailed is returned by PollBuild when the build reaches \"failed\".\n\n```go\nvar ErrDeployFailed = errors.New(\"deploy failed\")\n```\nErrDeployFailed is returned by PollBuild when the new rollout cannot become healthy: the image can't be pulled, or the app keeps crashing.\n\n```go\nvar ErrEmptyResponse = errors.New(\"the API returned an empty response; retry, and report it if it keeps happening\")\n```\nErrEmptyResponse covers a 2xx answer with no payload: nothing the caller did causes it and no command can continue past it.\n\n```go\nvar UserAgent = \"hostim-cli/dev\"\n```\nUserAgent is sent on every request so CLI traffic can be told apart from the console in the backend access logs. cmd sets it to the build version.\n\n## Functions\n\n```go\nfunc Check(status int, body []byte) error\n```\nCheck returns an \\*APIError if the response status is \u003e= 400, else nil. Generated response structs expose StatusCode() and a Body \\[]byte field, so callers use client.Check(resp.StatusCode(), resp.Body).\n\n```go\nfunc HasDockerfile(dir, dockerfile string) bool\n```\nHasDockerfile reports whether dir contains dockerfile, defaulting to \"Dockerfile\" when the path is empty.\n\n```go\nfunc IsStaticSite(dir string) bool\n```\nIsStaticSite reports whether dir looks like built static-site output: an index.html at its root and no Dockerfile.\n\n```go\nfunc MergeVars(base, updates []api.EnvVar) []api.EnvVar\n```\nMergeVars overlays updates onto base, replacing by name and appending new keys. The result is never nil, since the API rejects a null env array.\n\n```go\nfunc New(r config.Resolved) (*api.ClientWithResponses, error)\n```\nNew returns a ClientWithResponses that injects the Bearer token and transparently retries on 429 responses, honouring Retry-After.\n\n```go\nfunc NewAnonymous(apiURL string) (*api.ClientWithResponses, error)\n```\nNewAnonymous 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.\n\n```go\nfunc NormalizeApp(app *api.App)\n```\nNormalizeApp replaces nil required-array fields with empty slices so they serialize as \\[] rather than null, which the API schema rejects.\n\n```go\nfunc Pack(dir string, static bool) (path, sha256Hex string, size int64, err error)\n```\nPack writes a deterministic .tar.gz of dir to a temporary file and returns its path, hex SHA-256 and size. The same tree always gives the same hash, so a re-deploy is recognised as an existing upload. With static, dir is taken as built site output: every file is packed (a build folder is usually gitignored, and nothing in it reads .dockerignore), any root Dockerfile is replaced by an nginx one and the nginx config is added under .hostim/.\n\n```go\nfunc ResolveProjectID(ctx context.Context, cl *api.ClientWithResponses, ref string) (string, error)\n```\nResolveProjectID maps a project reference (friendly name or ID) to the ID the API expects in the {projectName} path parameter. An ID (hpr-…) is returned as-is; a name is looked up via GetProjects. Callers pass whatever the user typed, so both work everywhere a project is referenced.\n\n```go\nfunc StaticFallback(dir, dockerfile string) bool\n```\nStaticFallback reports whether a source that names dockerfile should be served as a static site instead: only for the default Dockerfile path, when dir has none but has an index.html.\n\n```go\nfunc Upload(ctx context.Context, c *api.ClientWithResponses, project, dir string, static bool, progress func(string)) (string, error)\n```\nUpload packs dir and stores it through the API, returning the archive's sha256. static packs dir as a static site (see Pack). progress, when set, is called with short status lines.\n\n## Types\n\n```go\ntype APIError struct {\n\tStatus  int\n\tCode    string // GenericMessage.error, when present\n\tMessage string // GenericMessage.message, when present\n}\n```\nAPIError is a structured error built from a non-2xx API response.\n\n```go\nfunc (e *APIError) Error() string\n```\n\n```go\ntype Baseline struct {\n\tBuildStatus    api.AppStatusBuildStatus\n\tLastBuiltAt    *time.Time\n\tLastDeployedAt *time.Time\n\t// contains filtered or unexported fields\n}\n```\nBaseline is an existing app's state captured before a deploy changes it. The operator acts on a rebuild request asynchronously, so for a few seconds after the request the status still describes the previous build and rollout. The baseline tells those stale values apart from the ones this deploy produces.\n\n```go\nfunc NewBaseline(ctx context.Context, c *api.ClientWithResponses, project, app string) (*Baseline, error)\n```\nNewBaseline reads app's current status (and, after a failed build, its BuildFailed events) for PollBuild.\n\n```go\ntype BuildResult struct {\n\tBuildStatus   api.AppStatusBuildStatus\n\tRuntimeStatus api.AppStatusRuntimeStatus\n\tStatus        *api.AppStatus\n}\n```\nBuildResult is the terminal outcome of a deploy poll.\n\n```go\nfunc PollBuild(\n\tctx context.Context,\n\tc *api.ClientWithResponses,\n\tproject, app string,\n\tinterval time.Duration,\n\texpectBuild bool,\n\tsince *Baseline,\n\tonTick func(*api.AppStatus),\n) (BuildResult, error)\n```\nPollBuild polls an app's status until the deploy reaches a terminal state or the context is cancelled. onTick, if non-nil, is called with each observed status so callers can render progress.\n\nA git source (expectBuild) first waits for its build: succeeded moves on to the rollout, failed returns ErrBuildFailed. Then every deploy waits for the new rollout: running is success, imagePullBackoff is a definitive failure, and a crash seen on 3 consecutive polls is treated as one too; both return ErrDeployFailed. Other transient states (pending) keep polling.\n\nsince is the app's state before an update (nil for a create, which has no previous build or rollout to mistake for this one). With it set, a succeeded build counts only once lastBuiltAt moves past since, a failed one only once it is shown to be new, and the runtime status only once lastDeployedAt moves past since. lastDeployedAt is the creation time of the Deployment's newest ReplicaSet; the operator stamps hostim.dev/restarted-at into the pod template on every rebuild, so every deploy creates a new one.\n\n```go\ntype VolumeMount = struct {\n\tMountPath *string `json:\"mountPath,omitempty\"`\n\tName      *string `json:\"name,omitempty\"`\n}\n```\nVolumeMount matches the anonymous struct type of App.VolumeMounts, so it can be assigned directly.\n\n```go\nfunc ParseVolumeMounts(specs []string) ([]VolumeMount, error)\n```\nParseVolumeMounts turns \"name:/mount/path\" values into app volume mounts.\n\n","path":"github.com/hostimdev/cli/internal/client","name":"client","synopsis":"Package client builds an authenticated Hostim API client from resolved config and maps API error responses (including 429 rate limiting) into Go errors.","isRedistributable":true}
