startup

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package startup 管理服务启动前的初始化钩子及其清理工作。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	// Name 是钩子的稳定唯一名称。
	Name string
	// Start 在传输服务启动前执行。
	Start func(context.Context) error
	// Stop 在应用清理阶段执行。
	Stop func(context.Context) error
}

Hook 描述一项需要在服务启动前初始化并在退出时清理的工作。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 按注册顺序执行启动钩子,并按相反顺序清理已启动钩子。

func NewManager

func NewManager() *Manager

NewManager 创建空的启动钩子管理器。

func (*Manager) Register

func (m *Manager) Register(hooks ...Hook) error

Register 注册启动钩子,并拒绝空名称、空启动方法和重复名称。

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start 按注册顺序执行钩子,失败时逆序清理已经启动的钩子。

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop 按启动顺序的相反方向清理钩子,并汇总全部清理错误。

Jump to

Keyboard shortcuts

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