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.
Types ¶
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.