Documentation
¶
Index ¶
- func ShutdownProviders(providers []foundation.ServiceProvider) []foundation.ShutdownProvider
- func SignalContext(parent context.Context) (context.Context, context.CancelFunc)
- type ConfigPublisher
- type Hooks
- func (h *Hooks) FireBooted(app foundation.Application)
- func (h *Hooks) FireBooting(app foundation.Application)
- func (h *Hooks) FireTerminating(ctx context.Context)
- func (h *Hooks) OnBooted(callback func(foundation.Application))
- func (h *Hooks) OnBooting(callback func(foundation.Application))
- func (h *Hooks) OnTerminating(callback func(context.Context))
- type Manager
- func (m *Manager) BootProviders(ctx context.Context, app foundation.Application, ...) error
- func (m *Manager) HasBooted() bool
- func (m *Manager) Hooks() *Hooks
- func (m *Manager) LastError() error
- func (m *Manager) MarkRunning() error
- func (m *Manager) RegisterProviders(ctx context.Context, publish ConfigPublisher, ...) error
- func (m *Manager) Registry() *Registry
- func (m *Manager) Run(ctx context.Context, runnable func(context.Context) error) error
- func (m *Manager) Shutdown(ctx context.Context, providers []foundation.ServiceProvider) error
- func (m *Manager) State() State
- type ProviderPhase
- type Registry
- func (r *Registry) BootedShutdownProviders() []foundation.ShutdownProvider
- func (r *Registry) MarkBooted(provider foundation.ServiceProvider)
- func (r *Registry) Phase(provider foundation.ServiceProvider) ProviderPhase
- func (r *Registry) Providers() []foundation.ServiceProvider
- func (r *Registry) RegisterOnce(provider foundation.ServiceProvider, ...) error
- type State
- type StateMachine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShutdownProviders ¶
func ShutdownProviders(providers []foundation.ServiceProvider) []foundation.ShutdownProvider
ShutdownProviders 按注册逆序返回实现了 ShutdownProvider 的实例。
Types ¶
type ConfigPublisher ¶
type ConfigPublisher func(provider foundation.ServiceProvider) error
ConfigPublisher 负责写入 Provider 默认配置。
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
Hooks 管理 Booting / Booted / Terminating 回调。
func (*Hooks) FireBooted ¶
func (h *Hooks) FireBooted(app foundation.Application)
func (*Hooks) FireBooting ¶
func (h *Hooks) FireBooting(app foundation.Application)
func (*Hooks) OnBooted ¶
func (h *Hooks) OnBooted(callback func(foundation.Application))
func (*Hooks) OnBooting ¶
func (h *Hooks) OnBooting(callback func(foundation.Application))
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 编排 Register、Boot、Run、Shutdown 阶段。
func (*Manager) BootProviders ¶
func (m *Manager) BootProviders(ctx context.Context, app foundation.Application, providers []foundation.ServiceProvider) error
BootProviders 触发 Booting 回调、Provider Boot、Booted 回调。
func (*Manager) RegisterProviders ¶
func (m *Manager) RegisterProviders(ctx context.Context, publish ConfigPublisher, providers ...foundation.ServiceProvider) error
RegisterProviders 对每个 Provider 仅执行一次 Register,并发布配置。
func (*Manager) Run ¶
Run 启动阻塞型 runnable,并在 context 取消后返回。
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown(ctx context.Context, providers []foundation.ServiceProvider) error
Shutdown 按 Provider 注册逆序关闭资源。
type ProviderPhase ¶
type ProviderPhase string
ProviderPhase 记录 Provider 已完成阶段。
const ( ProviderPhaseNone ProviderPhase = "" ProviderPhaseRegistered ProviderPhase = "registered" ProviderPhaseBooted ProviderPhase = "booted" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 跟踪已注册 Provider,避免重复 Register。
func (*Registry) BootedShutdownProviders ¶
func (r *Registry) BootedShutdownProviders() []foundation.ShutdownProvider
BootedProviders 按注册逆序返回已 Boot 的 ShutdownProvider。
func (*Registry) MarkBooted ¶
func (r *Registry) MarkBooted(provider foundation.ServiceProvider)
func (*Registry) Phase ¶
func (r *Registry) Phase(provider foundation.ServiceProvider) ProviderPhase
func (*Registry) Providers ¶
func (r *Registry) Providers() []foundation.ServiceProvider
Providers 返回按注册顺序排列的 Provider 列表。
func (*Registry) RegisterOnce ¶
func (r *Registry) RegisterOnce(provider foundation.ServiceProvider, register func(foundation.ServiceProvider) error) error
RegisterOnce 仅对尚未注册的 Provider 执行 register 回调,并记录顺序。
type State ¶
type State string
State 生命周期状态。
const ( StateCreated State = "created" StateRegistering State = "registering" StateRegistered State = "registered" StateBooting State = "booting" StateBooted State = "booted" StateRunning State = "running" StateStopping State = "stopping" StateStopped State = "stopped" StateFailed State = "failed" )
type StateMachine ¶
type StateMachine struct {
// contains filtered or unexported fields
}
StateMachine 并发安全的生命周期状态机。
func NewStateMachine ¶
func NewStateMachine() *StateMachine
func (*StateMachine) Is ¶
func (s *StateMachine) Is(states ...State) bool
func (*StateMachine) MustTransition ¶
func (s *StateMachine) MustTransition(next State)
func (*StateMachine) State ¶
func (s *StateMachine) State() State
func (*StateMachine) Transition ¶
func (s *StateMachine) Transition(next State) error
Source Files
¶
- hooks.go
- manager.go
- provider.go
- signal.go
- state.go
Click to show internal directories.
Click to hide internal directories.