Documentation
¶
Index ¶
- Constants
- type AppManager
- func (am *AppManager) AppConfig() *appconfig.AppConfig
- func (am *AppManager) ConfigDir() string
- func (am *AppManager) GetGlobalConfig() *serverconfig.Config
- func (am *AppManager) GetRuntimeServerPort() int
- func (am *AppManager) Initialized() bool
- func (am *AppManager) SetVersion(version string)
- func (am *AppManager) StartServerAt(port int) error
- type ServerManager
- func (sm *ServerManager) Cleanup()
- func (sm *ServerManager) GetGinEngine() *gin.Engine
- func (sm *ServerManager) GetTBServer() *server.Server
- func (sm *ServerManager) IsRunning() bool
- func (sm *ServerManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (sm *ServerManager) Setup(port int) error
- func (sm *ServerManager) Start() error
- func (sm *ServerManager) Stop() error
Constants ¶
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 ¶
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)