Documentation
¶
Index ¶
- Constants
- Variables
- func DisableZapScript(cfg *config.Instance) func()
- func IsServiceRunning(cfg *config.Instance) bool
- func LocalClient(ctx context.Context, cfg *config.Instance, method string, params string) (string, error)
- func ServiceState(cfg *config.Instance) (state string, ok bool)
- func WaitForAPI(cfg *config.Instance, maxWaitTime, checkInterval time.Duration) bool
- func WaitNotification(ctx context.Context, timeout time.Duration, cfg *config.Instance, id string) (string, error)
- func WaitNotifications(ctx context.Context, timeout time.Duration, cfg *config.Instance, ...) (method, params string, err error)
- type APIClient
- type LocalAPIClient
Constants ¶
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.
const APIPath = "/api/v0.1"
Variables ¶
Functions ¶
func DisableZapScript ¶
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
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
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
WaitForAPI waits for the service API to become available. Returns true if API became available, false if timeout reached.
func WaitNotification ¶
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
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.