app

package
v2.8.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package app assembles and runs the independently authenticated Canary HTTP and PWA host. It owns the app state directory, its single-process lock, device authentication, live view cache, alert delivery integration, and optional relay connector. Broker connectivity, trading decisions, and risk policy remain behind the typed daemon client and are not reimplemented here.

Index

Constants

View Source
const (
	DefaultAddr        = "0.0.0.0:8765"
	DefaultPairingTTL  = 5 * time.Minute
	DefaultPollEvery   = 5 * time.Second
	DefaultStressEvery = time.Minute
)

Default app-host settings cover the LAN-capable listen address, pairing lifetime, and local snapshot refresh intervals.

Variables

This section is empty.

Functions

func DefaultStateDir

func DefaultStateDir() string

DefaultStateDir returns the app-owned state directory selected from CANARY_APP_STATE_DIR, XDG_STATE_HOME, or the user's home directory, in that order. It does not create the directory.

func LoopbackAddrForLocalConnect

func LoopbackAddrForLocalConnect(addr string) string

LoopbackAddrForLocalConnect returns a host:port address suitable for a local client connecting to the app server. Wildcard hosts are replaced with 127.0.0.1, an empty value uses DefaultAddr, and non-host:port input is returned unchanged.

func PublicURLForAddr

func PublicURLForAddr(addr string) string

PublicURLForAddr returns the browser-visible URL for an app listen address. A wildcard host is replaced with the first usable LAN IPv4 address, falling back to 127.0.0.1 when none is available. An empty addr uses DefaultAddr. The result uses HTTP and preserves the listen port.

Types

type App

type App struct {
	Options Options
	Store   *state.Store
	Auth    *auth.Manager
	Live    *live.Service
	Relay   relay.Client
	Server  *hyperserve.Server
	// contains filtered or unexported fields
}

App is one configured Canary app-host process. New acquires exclusive ownership of Options.StateDir and populates the host components; Run starts their background loops and HTTP server. Close releases the process lock. Exported component fields expose app-local adapters, not broker authority.

func New

func New(opts Options) (*App, error)

New constructs an App and acquires the exclusive lock for opts.StateDir. If opts.Addr is empty, opts is replaced with DefaultOptions for opts.Version. The lock remains held until App.Close or the end of App.Run, and is released if construction fails. New opens app-local state and prepares the relay, but it does not start the HTTP server or background loops.

func (*App) Close

func (a *App) Close() error

Close releases the app state-directory lock. It is a no-op for a nil App or after the first call. Close does not itself stop the HTTP server; cancel the Run context to shut down a running App.

func (*App) Run

func (a *App) Run(ctx context.Context) error

Run starts live-cache polling, relay transport, credential reaping, and the HTTP server, then blocks until the server exits. Cancelling ctx stops the server and background contexts; normal cancellation and http.ErrServerClosed return nil. Run always calls App.Close before returning and must not be invoked concurrently on the same App.

type Options

type Options struct {
	Addr             string
	PublicURL        string
	PublicURLFromEnv bool
	Remote           bool
	RemoteURL        string
	StateDir         string
	SocketPath       string
	Version          string
	PairingTTL       time.Duration
	PollEvery        time.Duration
	StressEvery      time.Duration
}

Options configures one Canary app-host process. Durations control app-local pairing expiry and refresh cadence; SocketPath addresses the daemon's typed RPC socket. StateDir contains private grants and app delivery state and is protected by an exclusive process lock for the App lifetime.

func DefaultOptions

func DefaultOptions(version string) Options

DefaultOptions returns environment-aware defaults for an app host serving version. It reads the documented CANARY_APP_* variables, chooses the daemon socket and state directory defaults, and performs no network or filesystem writes.

Directories

Path Synopsis
Package alerts turns daemon-authored alert state into redacted app inbox records and Web Push work.
Package alerts turns daemon-authored alert state into redacted app inbox records and Web Push work.
Package auth manages Canary device pairing and app-session credentials.
Package auth manages Canary device pairing and app-session credentials.
Package daemonclient adapts the app host to the daemon's typed RPC surface.
Package daemonclient adapts the app host to the daemon's typed RPC surface.
Package apphttp registers the Canary app's authenticated HTTP routes and maps internal state and daemon RPC values onto explicit browser DTOs.
Package apphttp registers the Canary app's authenticated HTTP routes and maps internal state and daemon RPC values onto explicit browser DTOs.
Package live maintains the app host's refreshable daemon snapshot and publishes change events to local subscribers.
Package live maintains the app host's refreshable daemon snapshot and publishes change events to local subscribers.
Package push validates app-owned subscriptions and sends redacted Web Push payloads.
Package push validates app-owned subscriptions and sends redacted Web Push payloads.
Package relay connects the local Canary app host to an optional public relay.
Package relay connects the local Canary app host to an optional public relay.
Package state owns the Canary app's private durable state, including paired devices, push subscriptions, redacted inbox records, attention cursors, and app-local delivery evidence.
Package state owns the Canary app's private durable state, including paired devices, push subscriptions, redacted inbox records, attention cursors, and app-local delivery evidence.

Jump to

Keyboard shortcuts

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