Help us shape the future of Go! Take the 2026 Go Developer Survey

connector

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package connector is the Go client of the harness HTTP API, for every connector that runs in Go: the CLI and the TUI ship in the device binary and call the harness only through it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Login

func Login(ctx context.Context, token string) (c *Client, old *Client, version string, err error)

Login finds the harness of an api key, on this machine or through the pointer, checks that it takes the key, and saves both. It returns the client, the login it replaced (empty for none), and the release the harness runs.

func Path

func Path() (string, error)

Path is the login file, ~/.mainplane/login.json.

Types

type Client

type Client struct {
	URL     string `json:"url"`
	Key     string `json:"key"`
	Harness string `json:"harness"`
	Local   string `json:"-"`
	Mesh    string `json:"-"`
	// contains filtered or unexported fields
}

Client is what login wrote: the harness's key, the URL it was last found at, none when login found it on this machine, and the api key's secret. On the harness's own machine, calls go to it on loopback, at Local; on a worker of that harness, to its node on the mesh, at Mesh. A call that fails at URL finds the harness again, so one Client is shared, not copied.

func Load

func Load(ctx context.Context) (*Client, error)

Load is what login wrote, with the harness on loopback when it is the one installed on this machine, on the mesh when the worker on this machine follows the same harness key, else proved at its URL, or found again through the pointer and saved.

func (*Client) At added in v0.5.8

func (c *Client) At() string

At is the URL the harness was last found at.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method, path, ctype string, body io.Reader, out any) error

Call does one request, and decodes a JSON reply into out when out is given.

func (*Client) Create

func (c *Client) Create(ctx context.Context, cr harness.Create, via string) (string, error)

Create makes a session and returns its id.

func (*Client) Delete added in v0.5.4

func (c *Client) Delete(ctx context.Context, id, via string) error

Delete removes the session for good.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path, ctype string, body io.Reader) (*http.Response, error)

Do does one request; a status outside 2xx is an error in the harness's own words.

func (*Client) Find

func (c *Client) Find(ctx context.Context) error

Find proves the harness at its URL, or finds it again through the pointer and saves it.

func (*Client) Info

func (c *Client) Info(ctx context.Context, id string) (harness.Info, error)

func (*Client) Join added in v0.5.5

func (c *Client) Join(ctx context.Context) (string, error)

Join is the network name and device code that make a machine a worker.

func (*Client) Network added in v0.5.5

func (c *Client) Network(ctx context.Context) (string, error)

Network is the state of the harness's tunnel: starting, ready, or its error.

func (*Client) NewKey added in v0.5.5

func (c *Client) NewKey(ctx context.Context, name string) (string, error)

NewKey mints an api key named name and returns its token. A name in use is a StatusError of 409.

func (*Client) Post

func (c *Client) Post(ctx context.Context, id, via, text string, files []string) (int, error)

Post appends text and files as one turn: a single text/plain body, or one multipart part per piece, each typed by its extension. A file with no type is refused, not guessed. Returns the last record's n.

func (*Client) Providers added in v0.5.4

func (c *Client) Providers(ctx context.Context) ([]harness.ProviderInfo, error)

Providers lists the providers the harness serves, by the name a model starts with.

func (*Client) Records

func (c *Client) Records(ctx context.Context, id string, after int, wait string) ([]statefile.Record, error)

Records is the file after record n; with wait, a long poll.

func (*Client) Save

func (c *Client) Save() error

func (*Client) Sessions

func (c *Client) Sessions(ctx context.Context, status string, limit int) ([]harness.Info, error)

Sessions lists sessions, newest updated first.

func (*Client) SetDrive added in v0.5.5

func (c *Client) SetDrive(ctx context.Context, name, server string, workers []string) error

SetDrive makes or changes the drive name, served by server to workers, "*" for all.

func (*Client) SetName added in v0.5.4

func (c *Client) SetName(ctx context.Context, id, via, name string) error

SetName names the session; an empty name removes it.

func (*Client) SetProvider added in v0.5.4

func (c *Client) SetProvider(ctx context.Context, name, shape, u, region, session, key string) error

SetProvider makes the harness serve provider name with this shape, url, region, session header and key, at once.

func (*Client) SetWorkers

func (c *Client) SetWorkers(ctx context.Context, id, via string, ws []statefile.Worker) error

SetWorkers makes ws the session's workers from its next step on.

func (*Client) SignIn added in v0.5.5

func (c *Client) SignIn(ctx context.Context, name, shape, u string) (provider.LoginState, error)

SignIn starts provider name's login on the harness, with the shape and url for a provider it does not have, and returns its first prompt, or its end. The prompt may wait on a download, such as a provider's binary.

func (*Client) SignInPaste added in v0.5.5

func (c *Client) SignInPaste(ctx context.Context, name, text string) error

SignInPaste hands the login what its prompt asked the user to paste.

func (*Client) SignInWait added in v0.5.5

func (c *Client) SignInWait(ctx context.Context, name string) error

SignInWait waits for the login to end, and is an error unless it signed in.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context, id, via string) error

func (*Client) Version

func (c *Client) Version(ctx context.Context) (string, error)

Version is the release the harness runs.

func (*Client) Workers

func (c *Client) Workers(ctx context.Context) ([]Worker, error)

Workers lists the workers the harness knows.

type StatusError added in v0.5.5

type StatusError struct {
	Code int
	Text string
}

StatusError is a reply outside 2xx, in the harness's own words.

func (*StatusError) Error added in v0.5.5

func (e *StatusError) Error() string

type Worker

type Worker struct {
	Name        string `json:"name"`
	Refused     string `json:"refused,omitempty"`
	DriveServer bool   `json:"drive_server,omitempty"`
}

Worker is a worker as GET /workers lists it: connected, unless refused, and whether it can serve drives.

Directories

Path Synopsis
tui
Package tui is the Mainplane terminal app: a retained tree of components on the term engine, and its screens: login, and the session.
Package tui is the Mainplane terminal app: a retained tree of components on the term engine, and its screens: login, and the session.
term
Package term owns the terminal for a full screen app: raw mode and the alternate screen with a guaranteed restore, capability queries, input decoding, a cell buffer and a diff renderer.
Package term owns the terminal for a full screen app: raw mode and the alternate screen with a guaranteed restore, capability queries, input decoding, a cell buffer and a diff renderer.

Jump to

Keyboard shortcuts

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