lifecycle

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package lifecycle 定义服务生命周期钩子的抽象。

它将启动/停止划分为四个阶段:BeforeStart、AfterStart、BeforeStop、AfterStop。 启动阶段(Before/AfterStart)按注册顺序(FIFO)执行; 停止阶段(Before/AfterStop)按注册的逆序(LIFO)执行, 以保证资源按「后初始化先释放」的顺序安全清理。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecFunc

type ExecFunc = func(context.Context) error

ExecFunc 是生命周期钩子的执行函数签名。

func WrapNoCtx

func WrapNoCtx(fn func() error) ExecFunc

WrapNoCtx 将一个不接收 context 的函数适配为 ExecFunc。

func WrapNoCtxErr

func WrapNoCtxErr(fn func()) ExecFunc

WrapNoCtxErr 将一个既不接收 context 也不返回 error 的函数适配为 ExecFunc。

func WrapNoError

func WrapNoError(fn func(context.Context)) ExecFunc

WrapNoError 将一个无返回值的函数适配为 ExecFunc。

type Executor

type Executor struct {
	Exec ExecFunc
}

Executor 包装一个生命周期钩子函数。

type Getter

type Getter interface {
	GetAfterStops() []Executor
	GetBeforeStops() []Executor
	GetAfterStarts() []Executor
	GetBeforeStarts() []Executor
}

Getter 提供读取各阶段已注册钩子的能力(读取侧)。

type Handler

type Handler func(lc Lifecycle)

Handler 用于在构建期向 Lifecycle 注册钩子。

type Lifecycle

type Lifecycle interface {
	AfterStop(f ExecFunc)
	BeforeStop(f ExecFunc)
	AfterStart(f ExecFunc)
	BeforeStart(f ExecFunc)
}

Lifecycle 提供注册各阶段钩子的能力(写入侧)。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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