Documentation
¶
Overview ¶
Package xruntime provides application runtime bootstrapping, configuration loading, directory provisioning, embedded asset extraction, logging, and database initialization.
Index ¶
Constants ¶
const ( // DirAppFSYAML is the default relative subfolder inside the user data directory where YAML config files reside. DirAppFSYAML string = "appfs/yaml" // FileSessionLog is the file name used for the active runtime session log. FileSessionLog string = "current.log" // FileConfigYAML is the primary YAML configuration file name. FileConfigYAML string = "config.yaml" // FileConfigJson is the cached JSON configuration file name generated from the parsed YAML. FileConfigJson string = "config.json" // FileSQLiteData is the default SQLite database file name. FileSQLiteData string = "sqlite.db" // CmdOptionAll is a constant indicating a blanket selection or replacement mode. CmdOptionAll string = "all" )
Variables ¶
This section is empty.
Functions ¶
func End ¶
func End(runtimeConfig *RuntimeConfig) error
End gracefully finalizes the given runtime configuration instance. It closes active log file handles and rotates the session log if size or duration limits are exceeded.
Parameters:
- runtimeConfig: The active runtime configuration instance to close.
Returns:
- error: An error if closing log files, rotating, or cleaning up fails, nil otherwise.
func Reset ¶ added in v0.0.2
func Reset( runtimeConfig *RuntimeConfig, preReset PreResetFunc, posReset PostResetFunc, ) error
Reset removes the application log and user data directories associated with the given runtime configuration.
Parameters:
- runtimeConfig: Target runtime configuration instance.
- preReset: Optional function executed before deleting directories. If provided, reset proceeds only if it returns (true, nil).
- posReset: Optional function executed after deleting directories.
Returns:
- error: An error if preReset returns an error or false, directory deletion fails, or posReset fails; nil otherwise.
Types ¶
type PostResetFunc ¶ added in v0.0.2
type PostResetFunc func() error
PostResetFunc represents a callback function executed after application runtime directories are deleted. It returns an error if post-reset cleanup operations fail.
type PreResetFunc ¶ added in v0.0.2
PreResetFunc represents a callback function executed prior to deleting application runtime directories. It returns a boolean flag indicating if reset should proceed and an error if pre-validation fails.
type RuntimeConfig ¶
type RuntimeConfig struct {
// AppName is the unique identifier name of the application.
AppName string `json:"appName"`
// Version is the semantic version string of the application.
Version string `json:"version"`
// Debug indicates whether debug mode is enabled.
Debug bool `json:"debug"`
// AppFS is the embedded filesystem holding default configurations, schemas, and assets.
AppFS embed.FS `json:"-"`
// UserLogDir is the directory path where application log files are stored.
UserLogDir string
// UserDataDir is the directory path where application data and configuration files are stored.
UserDataDir string
// UserFileSessionLog is the full file path to the active session log.
UserFileSessionLog string
// UserFileConfigJson is the full file path to the compiled JSON configuration cache.
UserFileConfigJson string
// UserFileConfigYAML is the full file path to the source YAML configuration file.
UserFileConfigYAML string
// UserFileSQLiteData is the full file path to the SQLite database file.
UserFileSQLiteData string
// UserDirSQLiteData is the directory containing the SQLite database.
UserDirSQLiteData string
// CurrentFileSessionLog is the open file descriptor for writing current session logs.
CurrentFileSessionLog *os.File
// CurrentDateTime is the timestamp string representing when the session was initiated.
CurrentDateTime string
// Logging contains structured logging configurations and handlers.
Logging xlog.LogHandler `json:"logging"`
// DBConfig contains database connection parameters and migration settings.
DBConfig xdb.DBConfig `json:"dbConfig"`
// Context is the root context governing the lifecycle of the runtime instance.
Context context.Context `json:"-"`
}
RuntimeConfig holds the runtime state, paths, configuration metadata, logger, and database connection for an application instance.
func NewRuntimeConfig ¶
func NewRuntimeConfig() *RuntimeConfig
NewRuntimeConfig creates a new uninitialized RuntimeConfig instance with a default background context.
Returns:
- *RuntimeConfig: A new instance of RuntimeConfig.
func Start ¶
func Start( appName string, appFS embed.FS, logDir string, dataDir string, ) (*RuntimeConfig, error)
Start initializes the runtime filesystem, loads configuration, connects to the database, and starts logging.
Parameters:
- appName: Unique name of the application used for directory partitioning.
- appFS: Embedded filesystem containing assets and initial configuration files.
- logDir: Optional custom directory path for logs (uses OS user log directory if empty).
- dataDir: Optional custom directory path for application data (uses OS user data directory if empty).
Returns:
- *RuntimeConfig: Fully initialized runtime configuration instance ready for operation.
- error: An error if any initialization phase (filesystem, config parsing, DB connection, logging) fails.
func (*RuntimeConfig) End ¶
func (rc *RuntimeConfig) End() error
End gracefully finalizes the runtime configuration, closing active log files and performing log rotations if needed.
Returns:
- error: An error if closing log files or archiving logs fails, nil otherwise.
func (*RuntimeConfig) Reset ¶ added in v0.0.2
func (rc *RuntimeConfig) Reset(preReset PreResetFunc, posReset PostResetFunc) error
Reset deletes the application log and user data directories associated with the runtime configuration.
Parameters:
- preReset: Optional callback executed before resetting directories.
- posReset: Optional callback executed after resetting directories.
Returns:
- error: An error if preReset fails or returns false, directory deletion fails, or posReset fails; nil otherwise.