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

company

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package company follows one AI-native company on the upstream rysh-server for a session bound to it (design 037, "Company Connect"): a REST client that reads the company's state with the read-only workspace key, and a follower that keeps a snapshot fresh from live NATS hints and a poll.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorized is the server refusing the key. It is the one error the
	// follower treats specially: the key was revoked from the dashboard (or the
	// company was deleted), and polling harder will not help.
	ErrUnauthorized = errors.New("the server rejected this company's key — reconnect from the dashboard")
)

Functions

func ActivitySubject

func ActivitySubject(workspaceID, companyID string) string

ActivitySubject and ProgressSubject are the two subjects a connected client follows; both sit inside the workspace namespace the key is scoped to.

func NATSWebSocketURL

func NATSWebSocketURL(serverURL string) string

NATSWebSocketURL turns the server's HTTP origin into the WebSocket origin the proxy speaks on.

func ProgressSubject

func ProgressSubject(workspaceID, companyID string) string

func ProxyPath

func ProxyPath(workspaceID string) string

ProxyPath is the upgrade path the proxy scopes by workspace. The API key is NOT in it: it rides in the X-API-Key upgrade header (upstream.NATSAPIKeyHeader), because a URL lands in access logs (F-86).

Types

type Client

type Client struct {
	BaseURL string
	APIKey  string
	HTTP    *http.Client
}

Client reads a company over the owner routes with a connect key.

func NewClient

func NewClient(baseURL, apiKey string) *Client

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, companyID string) (*msg.CompanySnapshot, error)

Fetch reads the whole company. The company record itself is required; every other resource is best-effort — a failure there is recorded in Link.LastError and the snapshot still carries what did load, so one broken endpoint never blanks the view. An authorization failure anywhere is returned as ErrUnauthorized, because it means the key, not the endpoint.

type Follower

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

Follower keeps one company's snapshot fresh: a REST fetch on start, on every live hint from the workspace NATS namespace, on demand (Refresh), and on a timer regardless. Every hint is only a reason to fetch; REST is the truth (design 037 §Architecture).

func New

func New(client *Client, companyID, workspaceID string, up config.UpstreamConfig, onSnapshot func(msg.CompanySnapshot)) *Follower

New builds a follower. onSnapshot is called on the follower's goroutine after every fetch and on every live/offline transition; it must not block.

func (*Follower) Refresh

func (f *Follower) Refresh()

Refresh asks for a fetch soon. Non-blocking; coalesces.

func (*Follower) Run

func (f *Follower) Run(ctx context.Context)

Run blocks until ctx is done.

func (*Follower) Snapshot

func (f *Follower) Snapshot() msg.CompanySnapshot

Snapshot returns the latest snapshot (a copy).

type LinkDescription

type LinkDescription string

LinkDescription is a one-line reading of a CompanyLink.

func DescribeLink(l msg.CompanyLink) LinkDescription

func (LinkDescription) String

func (l LinkDescription) String() string

String describes the link for logs and ##company status.

Jump to

Keyboard shortcuts

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