app

package
v1.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRestartRequested = errors.New("server restart requested")

ErrRestartRequested is returned after a clean shutdown when a configuration change requires the next startup to enter a restricted guide.

Functions

func Start

func Start(listenAddr string)

Start builds an App and runs it through the full startup lifecycle: bootstrap, first-run install guide, database migration, metric store connection/recovery, and finally the normal serving loop. It blocks until the process should exit; a fatal error at any phase logs and exits the process, so a normal return means a clean, voluntary stop (e.g. an incomplete install/recovery guide).

Types

type App

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

App owns the server lifecycle. Individual phases live in focused files: bootstrap, metric store, providers, guide, scheduled, and runtime.

func New

func New(options Options) *App

New constructs an empty application. Initialization happens in the explicit lifecycle phases called by the command entrypoint.

func (*App) Bootstrap

func (a *App) Bootstrap() error

Bootstrap initializes the primary database and settings. Feature-owned data directories (theme, plugin, ...) are created lazily by their own packages on first use, not pre-created here.

func (*App) BuildRouter

func (a *App) BuildRouter() error

BuildRouter constructs the normal application router and starts reloads.

func (*App) ConnectMetricStore

func (a *App) ConnectMetricStore() error

ConnectMetricStore performs one connection attempt and registers cleanup only after a store has actually opened.

func (*App) ConnectMetricStoreWithRetry

func (a *App) ConnectMetricStoreWithRetry() error

ConnectMetricStoreWithRetry retries the monitoring database connection.

func (*App) DatabaseMigrationRequired

func (a *App) DatabaseMigrationRequired() (DatabaseMigrationRequirement, error)

DatabaseMigrationRequired checks both supported migration inputs before the normal Metric Store connection is initialized. Structure upgrades run first when both inputs exist, then the startup loop detects the legacy tables on its next pass.

func (*App) InitProviders

func (a *App) InitProviders() error

InitProviders initializes providers needed by the normal application.

func (*App) InitStores

func (a *App) InitStores() error

InitStores opens the metric store and starts its report batcher. Historical data migrations are started only through an explicit administrator action.

func (*App) InstallRequired

func (a *App) InstallRequired() (bool, error)

InstallRequired reports whether the instance still needs the first-run guide.

func (*App) Run

func (a *App) Run() error

Run starts the normal HTTP server and blocks until shutdown or fatal error.

func (*App) RunDatabaseMigration

func (a *App) RunDatabaseMigration(requirement DatabaseMigrationRequirement) (bool, error)

RunDatabaseMigration serves the same authenticated guide and status model for either migration input while leaving each conversion engine independent.

func (*App) RunInstallGuide

func (a *App) RunInstallGuide() (bool, error)

RunInstallGuide exposes only first-run installation APIs. It intentionally does not mount authentication or normal application routes.

func (*App) RunMetricStoreRecovery

func (a *App) RunMetricStoreRecovery(initialErr error) (bool, error)

RunMetricStoreRecovery keeps login available while exposing only the administrator-protected metric-store recovery API.

func (*App) Shutdown

func (a *App) Shutdown() error

Shutdown stops HTTP first, then releases registered resources in LIFO order.

func (*App) StartBackground

func (a *App) StartBackground() error

StartBackground starts scheduled work after all stores are ready.

type DatabaseMigrationRequirement

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

func (DatabaseMigrationRequirement) Required

func (r DatabaseMigrationRequirement) Required() bool

type Options

type Options struct {
	ListenAddr string
}

Options configures the process-wide application runtime.

type ReloadManager

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

ReloadManager 统一收敛所有配置热重载逻辑。

过去 kv.Subscribe 分散在 cmd/server.go、cors.go 等多处,导致:

  • 谁监听哪些 key 不清晰;
  • 某个 handler panic 会连带影响同一订阅回调里的其它逻辑;
  • 关闭时无法统一停止。

ReloadManager 把这些 handler 注册在一处,用单个 kv.Subscribe 分发, 并对每个 handler 做 panic 隔离。

func NewReloadManager

func NewReloadManager() *ReloadManager

NewReloadManager 创建一个空的热重载管理器。

func (*ReloadManager) Register

func (m *ReloadManager) Register(name string, handler func(kv.ConfigEvent))

Register 注册一个命名的热重载处理器。必须在 Start 之前调用。

func (*ReloadManager) Start

func (m *ReloadManager) Start()

Start 向 config 订阅一次,之后每个事件会分发给全部已注册 handler。 重复调用无副作用。

Jump to

Keyboard shortcuts

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