Introduction
eboot is the startup bootstrap module of ee-go, responsible for application initialization and startup flow. It parses command-line arguments, initializes the runtime environment (directories, configuration, logs, HTTP service, etc.), and provides the Ego struct as the application entry object. The New() function completes all initialization work, and the Run() method starts signal listening to keep the program running.
Import
import "github.com/wallace5303/ee-go/eboot"API
Ego
Description: ee-go application instance type, serving as the program entry object. After creation via New(), call the Run() method to start signal listening.
| Field | Type | Description |
|---|---|---|
| (no public fields) | — | Ego is an empty struct, all initialization state is stored in global modules |
New(staticFS)
Description: Create a new ee-go application instance and complete the full initialization flow. Includes: parsing command-line arguments, setting runtime environment variables, initializing directory structure, loading configuration, reading package.json, initializing user directories, initializing the logging system, and creating the HTTP service.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| staticFS | embed.FS | Yes | Embedded static filesystem, the public/ directory contents are embedded into the binary via the //go:embed directive |
Returns: *Ego — fully initialized ee-go application instance
Example:
package main
import (
"embed"
"github.com/wallace5303/ee-go/eboot"
)
//go:embed public
var staticFS embed.FS
func main() {
ego := eboot.New(staticFS)
ego.Run()
}Run()
Description: Start program signal listening, blocking and waiting for system signals (SIGINT, SIGTERM, SIGQUIT). After receiving a signal, it automatically executes the graceful exit flow. Internally calls eapp.Run().
Parameters: None
Returns: None
Example:
ego := eboot.New(staticFS)
ego.Run() // Blocks and runs until an exit signal is receivedSee also: eapp.Run()
CLI Flags
The New() function parses the following command-line arguments during initialization:
| Flag | Type | Default | Description |
|---|---|---|---|
-env | string | "prod" | Runtime environment, options: "dev" or "prod" |
-basedir | string | "./" | Application base directory path |
-port | string | "0" | HTTP service port, "0" means use the port from the configuration file |
-ssl | string | "false" | Whether to enable HTTPS/WSS, options: "true" or "false" |
-debug | string | "false" | Whether to enable debug mode, options: "true" or "false" |
Example:
# Start in development mode with specified port and debug
go run main.go -env=dev -port=8080 -debug=true
# Start in production mode with specified base directory
./app -env=prod -basedir=/opt/myapp -ssl=trueInitialization Flow
Initialization order executed by New() (immutable):
- Parse command-line arguments, set
eruntimeglobal variables - Set embedded static filesystem (
estatic.StaticFS) - Initialize directories (
eruntime.InitDir()) - Initialize configuration (
econfig.Init()) - Read package.json, get application name (
eapp.ReadPackage()) - Initialize user directories (create
~/.config/{appName},~/.{appName}, data, logs, tmp directories) - Initialize core log (
elog.InitCoreLog()) - Initialize business log (
elog.InitLog()) - Create HTTP service (when
http.enableistruein configuration)
