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:
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.
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.
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
- type Client
- func (c *Client) Delete(ctx context.Context, path string, out any) error
- func (c *Client) Dial(ctx context.Context, path string, query url.Values, subprotocol string) (*websocket.Conn, error)
- func (c *Client) Get(ctx context.Context, path string, out any) error
- func (c *Client) GetAbsolute(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) Post(ctx context.Context, path string, body, out any) error
- func (c *Client) Put(ctx context.Context, path string, body, out any) error
- func (c *Client) Raw(ctx context.Context, method, path string, body []byte) (RawResponse, error)
- type Config
- type RawResponse
Constants ¶
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 (*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) GetAbsolute ¶
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 ¶
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) Raw ¶
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.