client

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package client is how every presentation (CLI now, TUI in 1c, and the shared rules the web console relies on) reaches the local OVDB server.

Local is the single place that decides, for each capability, whether to ask the running server or to read state files, and it applies one rule set on the way: a running server started for a different OVDB home — or on a port other than an explicitly requested one — is a server_config_mismatch; a version difference is a one-line notice; a command that needs the server starts it unless told not to. Every method returns the schema-1 document bytes a presentation renders or prints as --json.

See decision 0006 and spec/features/local-server-and-web-console (REQ:client-values-and-mismatch, REQ:auto-start, REQ:version-mismatch-notice).

Index

Constants

View Source
const (
	ServerPath     = "/api/local/v1/server"
	StatusPath     = "/api/local/v1/status"
	LoginLinksPath = "/api/local/v1/login-links"
	ConfigPath     = "/api/local/v1/config"
)

Local API paths.

Variables

This section is empty.

Functions

func NotRunning

func NotRunning() *envelope.Error

NotRunning is server_not_running for --no-start.

func VersionNotice

func VersionNotice(serverVersion, clientVersion string) string

VersionNotice is the one line printed when client and server versions differ (REQ:version-mismatch-notice).

Types

type Client

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

Client talks to one running local server with its instance secret.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body any) (Response, error)

Do calls the local API. A failure status comes back as the server's *envelope.Error.

type Local

type Local struct {
	Dirs         paths.Dirs
	Version      string // this client's version
	Port         int    // resolved with setup.ResolvePort
	ExplicitPort bool   // --port or OVDB_PORT
	// Command builds the detached server process for a port.
	Command func(port int) *exec.Cmd
	// Notices receives one-line notices: auto-start, version mismatch,
	// directory warnings, unreadable runtime files. Never stdout with --json.
	Notices io.Writer
}

Local is one presentation's view of this home's local server.

func (*Local) Config

func (l *Local) Config(ctx context.Context) ([]byte, error)

Config is the configuration document.

func (*Local) Connect

func (l *Local) Connect(ctx context.Context, noStart bool) (*Client, error)

Connect returns a client for the running server, starting it when needed unless noStart (REQ:auto-start).

func (l *Local) LoginLink(ctx context.Context, noStart bool) ([]byte, error)

LoginLink creates a console login link, starting the server unless noStart.

func (*Local) Restart

func (l *Local) Restart(ctx context.Context) (StartOutcome, error)

Restart stops the server, treating an unconfirmable stale process as not running, and starts it again on the resolved port.

func (*Local) Server

func (l *Local) Server(ctx context.Context) ([]byte, error)

Server is the server document: from the server when it runs, otherwise built from files (a pure read that never starts anything).

func (*Local) SetConfig

func (l *Local) SetConfig(ctx context.Context, change setup.ConfigChange) ([]byte, error)

SetConfig changes a setting through the running server. With no server it writes as the home's single writer under the locks instead of starting one, because the fix offered for a busy port (`ovdb config set server.port N`) must work while that port keeps the server from starting.

func (*Local) Start

func (l *Local) Start(ctx context.Context) (StartOutcome, error)

Start starts the server, or reports the one already running.

func (*Local) Status

func (l *Local) Status(ctx context.Context) ([]byte, error)

Status is the whole-setup status document (first-run-onboarding#REQ:status-command).

func (*Local) Stop

func (l *Local) Stop(ctx context.Context) (StopOutcome, error)

Stop stops this home's server. A record naming a process that is gone or was reused is "not running", not a failure.

type Response

type Response struct {
	Status int
	Body   []byte
}

Response is a local API response; Body is kept byte for byte so --json prints exactly what the API returned.

type StartOutcome

type StartOutcome struct {
	Body           []byte // GET /api/local/v1/server
	AlreadyRunning bool
}

StartOutcome is a start's server document.

type StopOutcome

type StopOutcome struct {
	Body       []byte // the not-running server document
	WasRunning bool
}

StopOutcome is a stop's server document.

Jump to

Keyboard shortcuts

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