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

app

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 64 Imported by: 0

Documentation

Overview

Package app wires configuration, storage, auth primitives and HTTP handlers into a runnable server, and implements the rdpanel command line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(ctx context.Context, args []string, env config.LookupFunc, stdio Stdio) int

Main runs the command line and returns the process exit code (0 success, 1 failure, 2 usage error). args excludes the program name.

func NewLogger

func NewLogger(cfg config.LogConfig, w io.Writer) *slog.Logger

NewLogger builds the process logger from configuration.

Types

type App

type App struct {
	Config   *config.Config
	Log      *slog.Logger
	DB       *db.DB
	Store    *store.Store
	AEAD     *crypto.AEAD
	JWT      *auth.ClientJWT
	Hasher   *auth.Hasher
	Limiter  *auth.Backoff
	Registry *prometheus.Registry
	SPA      *web.SPA
	// WebFS is the built SPA (web/dist); /api/v1/docs serves api-docs.html and
	// its assets from it.
	WebFS fs.FS
	// Events is the in-process pub/sub behind /api/v1/events.
	Events *events.Bus
	// EventsAuth authenticates SSE streams (panel sessions, set by the admin
	// API wiring). nil denies every stream.
	EventsAuth events.Authenticator
	// HBBS is the hbbs/hbbr integration (presence, admin channel, reconciler).
	HBBS HBBS
	// Relays manages relays (local, static, agents), the computed hbbs relay
	// list and the agent hub at /agent/v1/*.
	Relays *relays.Service
	// Federation manages peer panels and federated relays (nil unless
	// RDPANEL_FEDERATION_ENABLED: no public endpoints, no sync loop).
	Federation *federation.Service
	// Kicks queues admin "disconnect" requests delivered by client heartbeats;
	// shared by the client API (Take) and the admin API (Kick).
	Kicks *clientapi.MemKickQueue
	// WebSessions maps web client session ids to panel users (ACL checks).
	WebSessions *websessions.Registry
	// ClientOptions are pushed to clients in heartbeat strategies; shared by
	// the client API (StrategyFor) and the admin API (/server/client-options).
	ClientOptions *clientopts.Service
	// TOTP verifies second factors; it implements clientapi's TOTPVerifier
	// (Enrolled/Verify) for the client /api/login tfa step.
	TOTP *adminapi.TOTPService
	// Mail sends e-mail codes and password reset links (internal/mailauth).
	Mail *mailauth.Service
	// LDAP manages directory synchronization and corporate authentication (internal/ldap).
	LDAP *ldap.Service
	// Webhook dispatches alerts for critical events (internal/webhook).
	Webhook *webhook.Service
	// StartedAt is when New ran (About page uptime).
	StartedAt time.Time
	// Updates is the cached GitHub release check (nil when
	// RDPANEL_UPDATE_CHECK=false).
	Updates *updatecheck.Checker
	// Clients looks up RustDesk releases for the "Install client" page (nil
	// when client downloads are disabled).
	Clients *clientdl.Service
	// Telemetry holds the login / client-token / audit counters.
	Telemetry *metrics.Panel

	// Logs is the in-memory buffer behind Server -> Logs (never nil after New).
	Logs *logs.Buffer
	// contains filtered or unexported fields
}

App holds every long-lived dependency. There are no package-level singletons; handlers receive what they need through their package's Deps.

func New

func New(ctx context.Context, cfg *config.Config, log *slog.Logger, opts ...Option) (*App, error)

New opens the database (applying migrations), loads keys and builds the App. Call Close when done.

func (*App) Close

func (a *App) Close() error

Close releases resources.

func (*App) Handler

func (a *App) Handler() http.Handler

Handler builds the root HTTP handler:

/healthz, /metrics
/api/v1/admin/*  panel API (stream B)
/api/v1/events   SSE (stream C)
/api/v1/openapi.{yaml,json}, /api/v1/docs  API contract + Swagger UI
/api/*           RustDesk client API (stream A)
/agent/v1/*      relay agent hub (enroll, WebSocket session)
/agent/install.sh relay agent installer (static script, no auth)
/s/*             public server share pages (RDPANEL_SHARE_LINKS_ENABLED; 404 when off)
/internal/hbbs/authorize  connection authorization for hbbs (loopback + secret)
/*               embedded SPA

func (*App) Serve

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

Serve listens on the configured address and blocks until ctx is cancelled, then shuts down gracefully. Background workers run for the server's lifetime.

func (*App) ServeListener

func (a *App) ServeListener(ctx context.Context, ln net.Listener) error

ServeListener is Serve on an existing listener (tests use 127.0.0.1:0).

type HBBS

type HBBS struct {
	Presence   *presence.Poller
	Control    *control.Client
	Reconciler *reconcile.Reconciler
	// RelayStats samples hbbr "usage" for the relay metrics.
	RelayStats *relaystats.Poller
}

HBBS groups the hbbs/hbbr integration. Fields are nil when the integration is disabled (RDPANEL_HBBS_ENABLED=false); Control/Reconciler are also nil when the configured addresses are not loopback (the admin channel only accepts loopback peers).

type Option added in v0.3.0

type Option func(*App)

Option customises New.

func WithLogBuffer added in v0.3.0

func WithLogBuffer(b *logs.Buffer) Option

WithLogBuffer makes the app serve Server -> Logs from b (created by the caller before the logger, so the panel's own startup lines are captured).

type Stdio

type Stdio struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
}

Stdio bundles the process streams so the CLI is testable.

Jump to

Keyboard shortcuts

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