fix(bootstrap module): add bootstrap module to meet future function (#674)

* fix(bootstrap module): add bootstrap module to meet future function

* Fix readme

* Fix panic because log.logger is nil

* fix import

---------

Co-authored-by: zbhan <zbhan@freewheel.tv>
This commit is contained in:
Shui
2025-11-06 21:53:10 -05:00
committed by GitHub
parent a8a2b6b849
commit 179e5c69bf
7 changed files with 769 additions and 189 deletions

27
bootstrap/hook_builder.go Normal file
View File

@@ -0,0 +1,27 @@
package bootstrap
// Hook 初始化钩子
type Hook struct {
Name string // 钩子名称(模块名)
Priority int // 优先级(越小越先执行)
Func func(*Context) error // 初始化函数
Enabled func(*Context) bool // 条件函数,返回 false 则跳过
ErrorPolicy ErrorPolicy // 错误处理策略
}
// HookBuilder 钩子构建器(用于链式调用)
type HookBuilder struct {
hook *Hook
}
// EnabledIf 设置条件函数(链式调用)
func (b *HookBuilder) EnabledIf(fn func(*Context) bool) *HookBuilder {
b.hook.Enabled = fn
return b
}
// OnError 设置错误处理策略(链式调用)
func (b *HookBuilder) OnError(policy ErrorPolicy) *HookBuilder {
b.hook.ErrorPolicy = policy
return b
}