Skip to content

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

go
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.

FieldTypeDescription
(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:

ParameterTypeRequiredDescription
staticFSembed.FSYesEmbedded 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:

go
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:

go
ego := eboot.New(staticFS)
ego.Run() // Blocks and runs until an exit signal is received

See also: eapp.Run()


CLI Flags

The New() function parses the following command-line arguments during initialization:

FlagTypeDefaultDescription
-envstring"prod"Runtime environment, options: "dev" or "prod"
-basedirstring"./"Application base directory path
-portstring"0"HTTP service port, "0" means use the port from the configuration file
-sslstring"false"Whether to enable HTTPS/WSS, options: "true" or "false"
-debugstring"false"Whether to enable debug mode, options: "true" or "false"

Example:

bash
# 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=true

Initialization Flow

Initialization order executed by New() (immutable):

  1. Parse command-line arguments, set eruntime global variables
  2. Set embedded static filesystem (estatic.StaticFS)
  3. Initialize directories (eruntime.InitDir())
  4. Initialize configuration (econfig.Init())
  5. Read package.json, get application name (eapp.ReadPackage())
  6. Initialize user directories (create ~/.config/{appName}, ~/.{appName}, data, logs, tmp directories)
  7. Initialize core log (elog.InitCoreLog())
  8. Initialize business log (elog.InitLog())
  9. Create HTTP service (when http.enable is true in configuration)