client

package
v2.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceStateStarting = "starting"
	ServiceStateReady    = "ready"
	ServiceStateFailed   = "failed"
)

Service lifecycle states reported by /health. They mirror api.ServiceState; this package cannot import pkg/api, which imports this one.

View Source
const APIPath = "/api/v0.1"

Variables

View Source
var (
	ErrRequestTimeout   = errors.New("request timed out")
	ErrInvalidParams    = errors.New("invalid params")
	ErrRequestCancelled = errors.New("request cancelled")
)

Functions

func DisableZapScript

func DisableZapScript(cfg *config.Instance) func()

DisableZapScript disables the service running any processed ZapScript from tokens, and returns a function to re-enable it.

The service holds ZapScript disabled for as long as this process's connection is open, so a process that is killed rather than exited cannot leave the service unusable. The returned function must still be run on a normal exit, even if there was an error, so ZapScript is re-enabled promptly.

func IsServiceRunning added in v2.9.0

func IsServiceRunning(cfg *config.Instance) bool

IsServiceRunning checks if a Zaparoo service is running on the configured port.

func LocalClient

func LocalClient(
	ctx context.Context,
	cfg *config.Instance,
	method string,
	params string,
) (string, error)

LocalClient sends a single unauthenticated method with params to the local running API service, waits for a response until timeout then disconnects.

func ServiceState added in v2.18.0

func ServiceState(cfg *config.Instance) (state string, ok bool)

ServiceState asks the local /health route what the service is doing.

This is the only way to tell the three cases apart: a process that is alive and working through startup, one that is alive but stopped on something a person has to resolve, and nothing listening at all. IsServiceRunning cannot, because it asks over the JSON-RPC route, which only answers once startup has finished — that is deliberate, so callers waiting for a usable service keep waiting.

ok is false when nothing answered.

func WaitForAPI added in v2.9.0

func WaitForAPI(cfg *config.Instance, maxWaitTime, checkInterval time.Duration) bool

WaitForAPI waits for the service API to become available. Returns true if API became available, false if timeout reached.

func WaitNotification

func WaitNotification(
	ctx context.Context,
	timeout time.Duration,
	cfg *config.Instance,
	id string,
) (string, error)

func WaitNotifications added in v2.9.0

func WaitNotifications(
	ctx context.Context,
	timeout time.Duration,
	cfg *config.Instance,
	ids ...string,
) (method, params string, err error)

WaitNotifications waits for any of the specified notification types on a single WebSocket connection. Returns the notification method that matched and its params.

Types

type APIClient added in v2.9.0

type APIClient interface {
	// Call executes a JSON-RPC method and returns the result.
	Call(ctx context.Context, method, params string) (string, error)

	// WaitNotification blocks until a notification of the given type is received.
	WaitNotification(ctx context.Context, timeout time.Duration, notificationType string) (string, error)
}

APIClient abstracts API communication for testability.

type LocalAPIClient added in v2.9.0

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

LocalAPIClient implements APIClient using the real local WebSocket client.

func NewLocalAPIClient added in v2.9.0

func NewLocalAPIClient(cfg *config.Instance) *LocalAPIClient

NewLocalAPIClient creates an APIClient that communicates with the local API.

func (*LocalAPIClient) Call added in v2.9.0

func (c *LocalAPIClient) Call(ctx context.Context, method, params string) (string, error)

Call executes a JSON-RPC method via the local WebSocket client.

func (*LocalAPIClient) WaitNotification added in v2.9.0

func (c *LocalAPIClient) WaitNotification(
	ctx context.Context,
	timeout time.Duration,
	notificationType string,
) (string, error)

WaitNotification waits for a notification via the local WebSocket client.

Jump to

Keyboard shortcuts

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