Introduction
Runtime environment module, provides global state variables and utility functions for application runtime. Includes version number, environment identifier, application name, platform type, directory paths, HTTP service status, and other global information, as well as environment detection and path retrieval functions.
Import
import "github.com/wallace5303/ee-go/eruntime"API
Version
Description: Framework version number, default value is "0.1.0".
Type: string
ENV
Description: Runtime environment identifier, value is "dev" or "prod", default value is "dev".
Type: string
AppName
Description: Application name, default is empty string, assigned by business code at startup.
Type: string
Platform
Description: Client platform type, value is "pc", "mobile", or "web", default value is "pc".
Type: string
IsExiting
Description: Indicates whether the application is exiting, default value is false. The task module checks this flag when adding or executing tasks; if true, task operations are skipped.
Type: bool
Debug
Description: Whether debug mode is enabled, default value is false.
Type: bool
BaseDir
Description: Application root directory path, initialized by getting the current working directory via os.Getwd().
Type: string
PublicDir
Description: Static resource directory path, set to BaseDir + "/public" by InitDir().
Type: string
UserHomeDir
Description: Operating system user home directory path.
Type: string
UserHomeConfDir
Description: Configuration file directory path under the operating system user home directory.
Type: string
UserHomeAppDir
Description: Application data directory path under the operating system user home directory.
Type: string
WorkDir
Description: Application work directory path.
Type: string
DataDir
Description: Application data storage directory path.
Type: string
TmpDir
Description: Application temporary data storage directory path.
Type: string
Port
Description: HTTP service listening port, default value is "0" (indicating not set).
Type: string
SSL
Description: Whether SSL is enabled, default value is false.
Type: bool
HttpServerIsRunning
Description: Whether the HTTP server is running, default value is false.
Type: bool
InitDir()
Description: Initialize the PublicDir directory path, setting it to filepath.Join(BaseDir, "public"). Should be called early in application startup.
Returns: No return value
Example:
eruntime.InitDir()
fmt.Println(eruntime.PublicDir) // Output: /path/to/app/publicIsProd()
Description: Check whether the current environment is production, i.e. ENV == "prod".
Returns: bool — true if in production environment, false otherwise
Example:
if eruntime.IsProd() {
fmt.Println("running in production mode")
}IsDev()
Description: Check whether the current environment is development, i.e. ENV == "dev".
Returns: bool — true if in development environment, false otherwise
Example:
if eruntime.IsDev() {
fmt.Println("running in development mode")
}IsDebug()
Description: Check whether debug mode is enabled, i.e. the value of Debug.
Returns: bool — true if debug is enabled, false otherwise
Example:
if eruntime.IsDebug() {
fmt.Println("debug mode is enabled")
}Pwd()
Description: Get the absolute path of the directory where the current executable file resides. Locates the executable via exec.LookPath, gets the absolute path via filepath.Abs, and finally returns its parent directory.
Returns: string — absolute path of the directory where the executable resides
Example:
dir := eruntime.Pwd()
fmt.Println("executable directory:", dir)