app

package
v1.261002.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MPL-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const StopTimeout = time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type AppManager

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

AppManager is the command process host: it owns AppConfig and server lifecycle. Domain behavior belongs in internal/usecase rather than here.

AppConfig is built lazily, on the first call that needs it. Building it is not free of side effects: appconfig.NewAppConfig creates the config directory tree, opens tingly.db (SQLite, WAL) through db.NewStoreManager and runs every store's AutoMigrate — in other words, it turns this process into a client of the server's database. A command that only needs the config directory (lock file, port file, log paths) must be able to run without any of that: `version` is what Docker's HEALTHCHECK runs every 30s, and `mcp-builtin` is a subprocess the running server itself spawns. Both used to open the database as a side effect of being dispatched, and on a Docker Desktop bind mount — where SQLite's cross-process locking is unreliable — that second writer corrupted a user's usage table (#1912).

So the rule is: ConfigDir and GetRuntimeServerPort never open the database; AppConfig and GetGlobalConfig do, once, on demand.

func NewAppManager

func NewAppManager(configDir string) (*AppManager, error)

NewAppManager creates an AppManager and builds its AppConfig immediately. An empty configDir means the default directory.

func NewAppManagerWithConfig

func NewAppManagerWithConfig(appConfig *appconfig.AppConfig) *AppManager

NewAppManagerWithConfig creates a new AppManager over an existing AppConfig.

func NewLazyAppManager added in v1.261001.1

func NewLazyAppManager(configDir string, onInitError func(error)) *AppManager

NewLazyAppManager creates an AppManager that builds its AppConfig on first use (AppConfig / GetGlobalConfig). An empty configDir means the default directory. onInitError, if non-nil, is called when that build fails; the CLI uses it to print the error and exit with the same message the eager path printed before.

func (*AppManager) AppConfig

func (am *AppManager) AppConfig() *appconfig.AppConfig

AppConfig returns the underlying AppConfig, building it on first call. This opens the database; see the type comment.

func (*AppManager) ConfigDir added in v1.261001.1

func (am *AppManager) ConfigDir() string

ConfigDir returns the configuration directory. It never builds AppConfig and never touches the database.

func (*AppManager) GetGlobalConfig

func (am *AppManager) GetGlobalConfig() *serverconfig.Config

GetGlobalConfig returns the global configuration manager, building AppConfig on first call.

func (*AppManager) GetRuntimeServerPort

func (am *AppManager) GetRuntimeServerPort() int

GetRuntimeServerPort returns the port the running server is actually listening on. The server port is intentionally not persisted in the config file, so a server started with --port would be invisible to other CLI processes; the server therefore records its port in a runtime port file next to the PID lock. When the server is running (lock held) and the port file is readable, that port wins; otherwise this falls back to the configured port.

Neither the lock nor the port file needs AppConfig, and the configured port is not stored in config.json (it is the build default unless set in-process), so this never opens the database — `stop`, `log` and `open` on a running server rely on that.

func (*AppManager) Initialized added in v1.261001.1

func (am *AppManager) Initialized() bool

Initialized reports whether AppConfig has been built (successfully).

func (*AppManager) SetVersion added in v1.261001.1

func (am *AppManager) SetVersion(version string)

SetVersion records the build version, applied to AppConfig when it is built (or immediately if it already is).

func (*AppManager) StartServerAt

func (am *AppManager) StartServerAt(port int) error

StartServerAt initializes and starts the in-process server used by the TUI.

type ServerManager

type ServerManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ServerManager manages the HTTP server lifecycle

func NewServerManager

func NewServerManager(appConfig *appconfig.AppConfig, opts ...server.ServerOption) *ServerManager

NewServerManager creates a new server manager. opts are server options passed directly to the underlying server.

func (*ServerManager) Cleanup

func (sm *ServerManager) Cleanup()

func (*ServerManager) GetGinEngine

func (sm *ServerManager) GetGinEngine() *gin.Engine

func (*ServerManager) GetTBServer

func (sm *ServerManager) GetTBServer() *server.Server

GetTBServer returns the underlying TinglyBox server instance

func (*ServerManager) IsRunning

func (sm *ServerManager) IsRunning() bool

IsRunning checks if the server is currently running

func (*ServerManager) ServeHTTP

func (sm *ServerManager) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ServerManager) Setup

func (sm *ServerManager) Setup(port int) error

Setup creates and configures the server without starting it

func (*ServerManager) Start

func (sm *ServerManager) Start() error

Start starts the server (requires Setup to be called first)

func (*ServerManager) Stop

func (sm *ServerManager) Stop() error

Stop stops the server gracefully

Jump to

Keyboard shortcuts

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