api

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 12 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 api is the only package that speaks HTTP to the Out Plane API.

It exists to contain three pieces of knowledge that would otherwise leak into every command:

  1. The response envelope. Every endpoint, success or failure, returns {data, statusCode, message, isSuccessful, error:{errors[], isShow}}. Commands should see a decoded result or an error, never that shape.

  2. The X-Team-Id header. It is required by most endpoints and, critically, is checked before any authentication logic runs. A missing header is a 400 even with a perfectly valid token, which is a confusing failure the client should make impossible rather than explain.

  3. The status code mapping, which is unusual on this API and gets misdiagnosed constantly: 403 means authorisation failed. It is not 401. 402 means a Hobby team hit a plan limit. 429 means a Pro team hit a plan limit. It is NOT rate limiting.

Index

Constants

View Source
const (
	VersionHeader     = "X-Outplane-Cli-Version"
	RecommendedHeader = "X-Outplane-Cli-Recommended"
)

VersionHeader carries this release's version so the API can refuse releases it no longer serves. RecommendedHeader comes back on every response and names the version this release ought to be.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to the Out Plane API.

It is created once per invocation and passed down. Nothing below this package constructs HTTP requests.

func New

func New(cfg Config) *Client

New creates a client.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, out any) error

Delete performs a DELETE.

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, path string, query url.Values, subprotocol string) (*websocket.Conn, error)

Dial opens a WebSocket to the API.

A socket gets everything a request gets: the same credential, the same team header, the same version header. The one thing it must not inherit is the client's timeout, which bounds a whole exchange and would cut a live session off after thirty seconds. Bounding the handshake alone is the transport's job, so this uses a client of its own.

The credential travels in Authorization, as it does everywhere else in this package. The console cannot do that, because a browser may not set headers on a handshake, and sends a "bearer.<jwt>" subprotocol instead which the API also accepts. There is no reason for a CLI to put a token somewhere a proxy will log it as a protocol name.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, out any) error

Get performs a GET and decodes data into out.

func (*Client) GetAbsolute

func (c *Client) GetAbsolute(ctx context.Context, rawURL string) ([]byte, error)

GetAbsolute fetches a full URL and returns the body untouched.

It exists for the log gateway, which is a different host and does not speak the API's response envelope: it answers with its own JSON, so the usual decode would look for a "data" field that is not there and report an empty result instead of a failure.

The credential and team headers are the same ones the API gets, because the gateway authorises against the same token.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body, out any) error

Post performs a POST with a JSON body and decodes data into out. A nil body sends no body at all, which several endpoints expect.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body, out any) error

Put performs a PUT with a JSON body.

func (*Client) Raw

func (c *Client) Raw(ctx context.Context, method, path string, body []byte) (RawResponse, error)

Raw performs a request this package knows nothing about.

It is the escape hatch's transport, and it deliberately keeps everything the ordinary path provides: the credential, the team header, the version header, and the same status mapping, so that a 403 through here exits the way a 403 through `app list` does. What it does not do is decode into a type, because there is no type to decode into.

type Config

type Config struct {
	BaseURL string
	Token   string
	TeamID  string
	Version string
	OSArch  string
	Timeout time.Duration
}

Config is what a Client needs to exist. A struct rather than positional arguments, because four strings in a row is a bug waiting to happen.

type RawResponse

type RawResponse struct {
	Status    int
	Data      json.RawMessage
	Envelope  json.RawMessage
	RequestID string
}

RawResponse is one arbitrary request's answer, kept in both shapes.

Data is what every other command would have decoded, and Envelope is the whole reply including the fields this package normally hides. Both are here because the caller is `outplane api`, whose reason to exist is that the CLI does not know what the caller is looking for.

Jump to

Keyboard shortcuts

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