Documentation
¶
Index ¶
- func GetCache() cache.Cache
- func GetConfigurator() config.Configurator
- func GetEventbus() eventbus.Eventbus
- func GetLockMaker() lock.Maker
- func GetLogger() log.Logger
- func GetTaskPool() task.Pool
- func SetCache(ca cache.Cache)
- func SetConfigurator(configurator config.Configurator)
- func SetEventbus(eb eventbus.Eventbus)
- func SetLockMaker(maker lock.Maker)
- func SetLogger(logger log.Logger)
- func SetTaskPool(pool task.Pool)
- type Container
- type ContainerError
- type ContainerOption
- func WithCloseTimeout(timeout time.Duration) ContainerOption
- func WithContext(ctx *Context) ContainerOption
- func WithDestroyTimeout(timeout time.Duration) ContainerOption
- func WithErrorHandler(handler ErrorHandler) ContainerOption
- func WithErrorRecoveryStrategy(strategy ErrorRecoveryStrategy) ContainerOption
- func WithExitOnError(exit bool) ContainerOption
- func WithOrderedClose(ordered bool) ContainerOption
- func WithRetryConfig(config *RetryConfig) ContainerOption
- type Context
- func (c *Context) AttachToPackages()
- func (c *Context) Cache() cache.Cache
- func (c *Context) Close() error
- func (c *Context) Configurator() config.Configurator
- func (c *Context) DetachFromPackages()
- func (c *Context) Eventbus() eventbus.Eventbus
- func (c *Context) IsAttached() bool
- func (c *Context) LockMaker() lock.Maker
- func (c *Context) Logger() log.Logger
- func (c *Context) SetCache(ca cache.Cache)
- func (c *Context) SetConfigurator(configurator config.Configurator)
- func (c *Context) SetEventbus(eb eventbus.Eventbus)
- func (c *Context) SetLockMaker(maker lock.Maker)
- func (c *Context) SetLogger(logger log.Logger)
- func (c *Context) SetTaskPool(pool task.Pool)
- func (c *Context) TaskPool() task.Pool
- type ErrorHandler
- type ErrorRecoveryStrategy
- type OrderedComponent
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfigurator ¶ added in v1.0.9
func GetConfigurator() config.Configurator
GetConfigurator 获取配置器
func SetConfigurator ¶ added in v1.0.9
func SetConfigurator(configurator config.Configurator)
SetConfigurator 设置配置器
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container 服务容器
func (*Container) ServeWithError ¶ added in v1.0.9
ServeWithError 启动容器并返回错误(不会调用 log.Fatal) 适用于测试或需要自定义错误处理的场景
type ContainerError ¶ added in v1.0.9
type ContainerError struct {
Phase string // 错误发生的阶段: init, start, close, destroy
Component string // 出错的组件名称
Err error // 原始错误
Retryable bool // 是否可重试
}
ContainerError 容器错误类型
func (*ContainerError) Error ¶ added in v1.0.9
func (e *ContainerError) Error() string
func (*ContainerError) Unwrap ¶ added in v1.0.9
func (e *ContainerError) Unwrap() error
type ContainerOption ¶ added in v1.0.9
type ContainerOption func(*Container)
ContainerOption 容器配置选项
func WithCloseTimeout ¶ added in v1.0.9
func WithCloseTimeout(timeout time.Duration) ContainerOption
WithCloseTimeout 设置组件关闭超时时间
func WithContext ¶ added in v1.0.9
func WithContext(ctx *Context) ContainerOption
WithContext 使用指定的上下文
func WithDestroyTimeout ¶ added in v1.0.9
func WithDestroyTimeout(timeout time.Duration) ContainerOption
WithDestroyTimeout 设置组件销毁超时时间
func WithErrorHandler ¶ added in v1.0.9
func WithErrorHandler(handler ErrorHandler) ContainerOption
WithErrorHandler 设置自定义错误处理器
func WithErrorRecoveryStrategy ¶ added in v1.0.9
func WithErrorRecoveryStrategy(strategy ErrorRecoveryStrategy) ContainerOption
WithErrorRecoveryStrategy 设置错误恢复策略
func WithExitOnError ¶ added in v1.0.9
func WithExitOnError(exit bool) ContainerOption
WithExitOnError 设置发生错误时是否退出程序(默认 true)
func WithOrderedClose ¶ added in v1.0.9
func WithOrderedClose(ordered bool) ContainerOption
WithOrderedClose 设置是否按顺序关闭组件(根据优先级)
func WithRetryConfig ¶ added in v1.0.9
func WithRetryConfig(config *RetryConfig) ContainerOption
WithRetryConfig 设置重试配置
type Context ¶ added in v1.0.9
type Context struct {
// contains filtered or unexported fields
}
Context 框架上下文,统一管理核心依赖 支持多实例场景(如测试),同时保持向后兼容
并发安全设计:
- Getter 方法使用 atomic.Value,无锁读取,高性能
- Setter 方法使用 sync.Mutex,保证写入原子性
- 适合读多写少的场景(Setter 只在初始化时调用)
func (*Context) AttachToPackages ¶ added in v1.0.9
func (c *Context) AttachToPackages()
AttachToPackages 将 Context 关联到各包的全局变量 调用后,各包的 Get 函数会优先从 Context 读取
func (*Context) Configurator ¶ added in v1.0.9
func (c *Context) Configurator() config.Configurator
Configurator 获取配置器(实现 config.ContextProvider 接口)
func (*Context) DetachFromPackages ¶ added in v1.0.9
func (c *Context) DetachFromPackages()
DetachFromPackages 解除 Context 与各包的关联
func (*Context) IsAttached ¶ added in v1.0.9
IsAttached 检查是否已关联到各包
func (*Context) SetConfigurator ¶ added in v1.0.9
func (c *Context) SetConfigurator(configurator config.Configurator)
SetConfigurator 设置配置器
func (*Context) SetEventbus ¶ added in v1.0.9
SetEventbus 设置事件总线
func (*Context) SetLockMaker ¶ added in v1.0.9
SetLockMaker 设置分布式锁制造器
func (*Context) SetTaskPool ¶ added in v1.0.9
SetTaskPool 设置任务池
type ErrorRecoveryStrategy ¶ added in v1.0.9
type ErrorRecoveryStrategy int
ErrorRecoveryStrategy 错误恢复策略
const ( // ErrorRecoveryNone 不进行恢复,直接失败 ErrorRecoveryNone ErrorRecoveryStrategy = iota // ErrorRecoveryRetry 重试策略 ErrorRecoveryRetry // ErrorRecoverySkip 跳过当前组件继续执行 ErrorRecoverySkip // ErrorRecoveryCallback 回调自定义处理函数 ErrorRecoveryCallback )
type OrderedComponent ¶ added in v1.0.9
type OrderedComponent interface {
component.Component
// Priority 返回组件优先级,数值越小优先级越高(越先关闭)
Priority() int
// Dependencies 返回依赖的组件名称列表
Dependencies() []string
}
OrderedComponent 有序组件接口,支持定义组件关闭顺序
type RetryConfig ¶ added in v1.0.9
type RetryConfig struct {
MaxRetries int // 最大重试次数
RetryDelay time.Duration // 重试间隔
Backoff float64 // 退避系数(每次重试间隔乘以该系数)
}
RetryConfig 重试配置
func DefaultRetryConfig ¶ added in v1.0.9
func DefaultRetryConfig() *RetryConfig
DefaultRetryConfig 默认重试配置
Directories
¶
| Path | Synopsis |
|---|---|
|
redis
module
|
|
|
gate
Package gate 提供网关组件,负责客户端连接管理和消息转发。
|
Package gate 提供网关组件,负责客户端连接管理和消息转发。 |
|
node
Package node 提供节点组件,负责业务逻辑处理和消息路由。
|
Package node 提供节点组件,负责业务逻辑处理和消息路由。 |
|
http
module
|
|
|
Package config 提供统一的配置管理接口和实现。
|
Package config 提供统一的配置管理接口和实现。 |
|
nacos
module
|
|
|
core
|
|
|
Package encoding 提供统一的编解码器接口和多种编码格式支持。
|
Package encoding 提供统一的编解码器接口和多种编码格式支持。 |
|
proto
Package proto 提供 Protocol Buffers 格式的编解码器实现。
|
Package proto 提供 Protocol Buffers 格式的编解码器实现。 |
|
redis
module
|
|
|
internal
|
|
|
redis
module
|
|
|
redis
module
|
|
|
Package network 定义了网络通信的核心接口,包括客户端、服务器和连接。
|
Package network 定义了网络通信的核心接口,包括客户端、服务器和连接。 |
|
ws
module
|
|
|
Package registry 提供服务注册发现的统一接口和实现。
|
Package registry 提供服务注册发现的统一接口和实现。 |
|
nacos
module
|
|
|
grpc
module
|
|
|
utils
|
|
