foundation

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapLifecycleError added in v1.1.0

func WrapLifecycleError(phase, provider, operation string, err error) error

WrapLifecycleError 构造带阶段信息的错误。

Types

type Application

type Application interface {
	Version() string

	GetBasePath() string
	GetBootstrapPath() string
	GetConfigPath() string
	GetLangPath() string
	GetPublicPath() string
	GetResourcePath() string
	GetStoragePath() string

	Environment(...string) (string, bool)
	MaintenanceMode() context.Context
	IsDownForMaintenance() bool
	SetMaintenanceMode(down bool)

	// RunMode returns the current shell mode (web/console/unknown).
	RunMode() RunMode

	// Register a service provider constructor with the application.
	Register(provider ...any) error
	Provide(function interface{}, opts ...dig.ProvideOption) error
	Invoke(function interface{}, opts ...dig.InvokeOption) error

	// Boot the application's service providers.
	Boot(ctx context.Context) error

	// Register a new boot listener.
	Booting(callback func(application Application))

	// Register a new "booted" listener.
	Booted(callback func(application Application))

	// Get the current application locale.
	GetLocale() string

	// Get the registered service provider instances if any exist.
	GetProviders(provider interface{}) []interface{}

	// Determine if the application has been bootstrapped before.
	HasBeenBootstrapped() bool

	// LifecycleState returns the current lifecycle state name.
	LifecycleState() string

	// Set the current application locale.
	SetLocale(locale string)

	// Register a terminating callback with the application.
	Terminating(callback interface{}) Application

	// Terminate the application.
	Terminate(ctx context.Context) error
}

Application 接口定义

type ApplicationAware added in v1.1.0

type ApplicationAware interface {
	SetApplication(app Application)
}

ApplicationAware 由需要访问 Application 的组件实现。 Application 会在 Register 或 Bootstrap 前通过该接口完成显式注入。

type ConfigValidator added in v1.1.0

type ConfigValidator interface {
	ValidateConfig(ctx context.Context) error
}

ConfigValidator 可选接口:Provider 可声明启动前配置校验。

type HealthProvider added in v1.1.0

type HealthProvider interface {
	HealthCheck(ctx context.Context) error
}

HealthProvider 可选接口:参与 readiness 聚合。

type LifecycleError added in v1.1.0

type LifecycleError struct {
	Phase     string
	Provider  string
	Operation string
	Cause     error
}

LifecycleError 描述应用生命周期阶段失败。

func (*LifecycleError) Error added in v1.1.0

func (e *LifecycleError) Error() string

func (*LifecycleError) Unwrap added in v1.1.0

func (e *LifecycleError) Unwrap() error

type RunMode added in v1.2.0

type RunMode string

RunMode identifies how the application shell was started.

const (
	// RunModeUnknown means Boot was invoked without WebShell/ConsoleShell.
	RunModeUnknown RunMode = ""
	// RunModeWeb means the application is serving HTTP traffic.
	RunModeWeb RunMode = "web"
	// RunModeConsole means the application is executing Cobra commands.
	RunModeConsole RunMode = "console"
)

type RunnableProvider added in v1.1.0

type RunnableProvider interface {
	RunWithContext(ctx context.Context) error
}

RunnableProvider 可选接口:阻塞型服务(如 HTTP Server)实现,支持 context 取消。

type ServiceProvider

type ServiceProvider interface {
	Register(ctx context.Context) error
	Boot(ctx context.Context) error
	Conf() map[string]string
	Description() string
}

ServiceProvider 服务提供者契约。 Register / Boot 必须返回 error,禁止在合法路径上 panic。

type ShutdownProvider added in v1.1.0

type ShutdownProvider interface {
	Shutdown(ctx context.Context) error
}

ShutdownProvider 可选接口:Provider 持有外部资源时实现,用于优雅关闭。

Source Files

  • application.go
  • errors.go
  • service_provider.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL