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

app

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 78 Imported by: 0

Documentation

Overview

Package app composes the application: it registers every singleton in the dependency container and starts and stops the servers, the event router and the job workers.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyStarted = errors.New("app: already started")

ErrAlreadyStarted means Start was called a second time; an App starts once.

View Source
var ErrE2EOnly = errors.New("app: option is only valid in the " + config.EnvE2E + " environment")

ErrE2EOnly means an end-to-end-only option was passed to an app that is not the e2e profile.

View Source
var ErrNotServable = errors.New("app: this app has no servers to start")

ErrNotServable means Start was called on an app that has no servers (the command app).

Functions

This section is empty.

Types

type App

type App struct {
	Config *config.Config
	Server *http.Server
	// Metrics is the opt-in Prometheus listener (ADR 0018); nil when SPHERICON_METRICS_ADDR
	// is empty and for the command app.
	Metrics *telemetry.MetricsServer
	// Internal is the opt-in internal listener: the edge's TLS ask (ADR 0038, always) and the
	// service endpoints (ADR 0026, with the `staff` license); nil when SPHERICON_INTERNAL_ADDR
	// is empty and for the command app.
	Internal *sidelistener.Server
	// contains filtered or unexported fields
}

func New

func New(env string, opts ...Option) (*App, error)

func NewCommandApp

func NewCommandApp(env string) (*App, error)

NewCommandApp builds the minimal app the commands need (config, database, ent client, system sender) without the HTTP server, the event router or the job workers. Providers are lazy, so only what a command invokes is ever constructed; that keeps `sphericon workspace …` quick to start and to shut down.

func (*App) Accounts

func (a *App) Accounts() (*accounts.Accounts, error)

Accounts is the product's Accounts module from the DI container, for harnesses that arrange users and Workspaces through the same instance the HTTP surface runs on (the end-to-end suite), so they open no second connection pool.

func (*App) Bus

func (a *App) Bus() (*events.Bus, error)

Bus is the event bus from the DI container, for harnesses that must change data inside a transaction (events.Bus.WithinScopedTx) like the product's own write paths.

func (*App) Close

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

Close cancels the event router and the job workers, waits for them to stop, shuts the HTTP servers down and then the container. Safe to call more than once and after a failed Start; every call returns the first call's result.

func (*App) CreateOwner

func (a *App) CreateOwner(ctx context.Context, email, name string) (string, error)

CreateOwner makes a Verified User with its first Workspace and a one-time password (ADR 0042): the way the first Owner of an Instance that closed sign-up comes to exist.

func (*App) CreateStaffMember

func (a *App) CreateStaffMember(ctx context.Context, email string) (string, error)

CreateStaffMember makes a platform Staff member (ADR 0026) and returns its one-time password: the only way a Staff member comes to exist (there is no signup). It refuses a duplicate email and an instance without the `staff` license.

func (*App) Done

func (a *App) Done() <-chan error

Done delivers, once, how the public server ended. A failure to serve arrives as an error; after a graceful Close the server ends cleanly and a nil error arrives, so a receiver must read nil as "stopped", not "still running". Nothing arrives if Start failed before serving. A binary waits on it next to its signals.

func (*App) IssueServiceCredential

func (a *App) IssueServiceCredential(ctx context.Context, in staff.IssueInput) (*staff.Issued, error)

IssueServiceCredential creates a Service credential (ADR 0026) and returns it with its value, shown once. Only the Staff member's command line makes one: no endpoint can.

func (*App) Reencrypt

func (a *App) Reencrypt(ctx context.Context) ([]rekey.Count, error)

Reencrypt seals every stored secret under the primary key of the encryption keyset (`sphericon encryption-key reencrypt`) and returns what it did per column.

func (*App) ResetSecondFactor

func (a *App) ResetSecondFactor(ctx context.Context, email string) (bool, error)

ResetSecondFactor clears the Second factor and Recovery codes of the User with this email and ends every session of theirs (ADR 0020), recorded as `user.second_factor_reset` by the Staff member "cli" in each of their Workspaces. It reports whether anything changed: a User without a Second factor is left as is.

func (*App) ResetStaffTOTP

func (a *App) ResetStaffTOTP(ctx context.Context, email string) error

ResetStaffTOTP clears the TOTP of the Staff member with this email and ends its sessions (ADR 0026): the only way a lost TOTP is reset. The Staff member re-enrols at next login. staff.ErrNotFound for an unknown email, ErrNotLicensed without the license.

func (*App) RevokeServiceCredential

func (a *App) RevokeServiceCredential(ctx context.Context, id int64) error

RevokeServiceCredential ends a Service credential.

func (*App) RotateServiceCredential

func (a *App) RotateServiceCredential(ctx context.Context, id int64, expiresAt *time.Time) (*staff.Issued, error)

RotateServiceCredential issues a new credential with the name and scopes of an active one, leaving the old one active until it is revoked.

func (*App) ServiceCredentials

func (a *App) ServiceCredentials(ctx context.Context, name string) ([]*ent.ServiceCredential, error)

ServiceCredentials lists the Service credentials with their state, narrowed to one service's by name when set.

func (*App) Shutdown

func (a *App) Shutdown(ctx context.Context) *do.ShutdownReport

func (*App) Start

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

Start brings the application up and returns without blocking: it binds the metrics listener, starts the domain-event router and the job queue, then serves the public HTTP server. It returns the first startup error after unwinding whatever it had already started (the container included), so a failed Start leaves nothing running.

Start owns its cancellation: it derives its own context from ctx, and Close cancels it. Done reports how the public server ends; Close stops everything. An App starts once: a second Start returns ErrAlreadyStarted, whether or not the first succeeded.

func (*App) SuspendWorkspace

func (a *App) SuspendWorkspace(ctx context.Context, publicID string, by suspension.Actor, reason string) (bool, error)

SuspendWorkspace freezes a Workspace's outbound sending (ADR 0007) and tells its owner(s) through the system sender. It reports whether anything changed; an already-suspended Workspace is left as it was and the owner is not told twice. If the notice cannot be sent the suspension still stands and the error says so.

func (*App) UnsuspendWorkspace

func (a *App) UnsuspendWorkspace(ctx context.Context, publicID string, by suspension.Actor) (bool, error)

UnsuspendWorkspace lifts a Workspace's suspension; held sends resume on their own.

type Option

type Option func(*options)

Option customises how New builds the App.

func WithE2EDKIMLookup

func WithE2EDKIMLookup() Option

WithE2EDKIMLookup swaps the DKIM DNS lookup for the development one, which echoes a Sending domain's own stored key, so the end-to-end suite verifies domains without real DNS while the development flag stays off. New refuses it outside the e2e profile, so it cannot be wired into a production configuration.

func WithListener

func WithListener(ln net.Listener) Option

WithListener makes the App serve on a listener the caller already opened (a free port, say). The configured public URL (SPHERICON_APP_URL, the base of unsubscribe, confirm and tracking links) and PORT are derived from the listener's address, so the order is: open the listener, then New, then Start. Close closes the listener.

Jump to

Keyboard shortcuts

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