Documentation
¶
Overview ¶
Package services 提供框架内置服务的实现 所有服务都实现了 core.Service 接口,支持自动依赖解析和并行初始化
内置服务列表:
- LoggerService: 日志服务(优先级0,无依赖)
- RedisService: Redis缓存服务(优先级10,依赖logger)
- MySQLService: MySQL数据库服务(优先级10,依赖logger)
- ElasticsearchService: Elasticsearch搜索服务(优先级20,依赖logger)
- RabbitMQService: RabbitMQ消息队列服务(优先级30,依赖logger)
- EtcdService: Etcd配置中心服务(优先级20,依赖logger)
- ScheduleService: 定时任务服务(优先级100,依赖logger)
使用示例:
// 注册自定义服务
core.RegisterService(&MyCustomService{})
// 注册初始化钩子
core.RegisterServiceHook("mysql", core.Hook{
Phase: core.AfterInit,
Fn: func(ctx context.Context, name string) error {
// 执行数据迁移
return nil
},
})
Package services 提供框架内置服务的实现 本文件实现了 OpenTelemetry 链路追踪服务
Index ¶
- type ElasticsearchService
- func (s *ElasticsearchService) Close(ctx context.Context) error
- func (s *ElasticsearchService) Dependencies() []string
- func (s *ElasticsearchService) HealthCheck(ctx context.Context) error
- func (s *ElasticsearchService) Init(ctx context.Context) error
- func (s *ElasticsearchService) Name() string
- func (s *ElasticsearchService) Priority() int
- func (s *ElasticsearchService) ShouldInit(cfg *config.BaseConfig) bool
- type EtcdService
- func (s *EtcdService) Close(ctx context.Context) error
- func (s *EtcdService) Dependencies() []string
- func (s *EtcdService) HealthCheck(ctx context.Context) error
- func (s *EtcdService) Init(ctx context.Context) error
- func (s *EtcdService) Name() string
- func (s *EtcdService) Priority() int
- func (s *EtcdService) ShouldInit(cfg *config.BaseConfig) bool
- type LoggerService
- func (s *LoggerService) Close(ctx context.Context) error
- func (s *LoggerService) Dependencies() []string
- func (s *LoggerService) Init(ctx context.Context) error
- func (s *LoggerService) Name() string
- func (s *LoggerService) Priority() int
- func (s *LoggerService) ShouldInit(cfg *config.BaseConfig) bool
- type MySQLService
- func (s *MySQLService) Close(ctx context.Context) error
- func (s *MySQLService) Dependencies() []string
- func (s *MySQLService) HealthCheck(ctx context.Context) error
- func (s *MySQLService) Init(ctx context.Context) error
- func (s *MySQLService) Name() string
- func (s *MySQLService) Priority() int
- func (s *MySQLService) ShouldInit(cfg *config.BaseConfig) bool
- type RabbitMQService
- func (s *RabbitMQService) Close(ctx context.Context) error
- func (s *RabbitMQService) Dependencies() []string
- func (s *RabbitMQService) Init(ctx context.Context) error
- func (s *RabbitMQService) Name() string
- func (s *RabbitMQService) Priority() int
- func (s *RabbitMQService) SetConsumerList(list []*config.MessageQueue)
- func (s *RabbitMQService) SetProducerList(list []*config.MessageQueue)
- func (s *RabbitMQService) ShouldInit(cfg *config.BaseConfig) bool
- type RedisService
- func (s *RedisService) Close(ctx context.Context) error
- func (s *RedisService) Dependencies() []string
- func (s *RedisService) HealthCheck(ctx context.Context) error
- func (s *RedisService) Init(ctx context.Context) error
- func (s *RedisService) Name() string
- func (s *RedisService) Priority() int
- func (s *RedisService) ShouldInit(cfg *config.BaseConfig) bool
- type ScheduleService
- func (s *ScheduleService) Close(ctx context.Context) error
- func (s *ScheduleService) Dependencies() []string
- func (s *ScheduleService) Init(ctx context.Context) error
- func (s *ScheduleService) Name() string
- func (s *ScheduleService) Priority() int
- func (s *ScheduleService) SetScheduleList(list []config.ScheduleInfo)
- func (s *ScheduleService) ShouldInit(cfg *config.BaseConfig) bool
- type TracingService
- func (s *TracingService) Close(ctx context.Context) error
- func (s *TracingService) Dependencies() []string
- func (s *TracingService) Init(ctx context.Context) error
- func (s *TracingService) Name() string
- func (s *TracingService) Priority() int
- func (s *TracingService) ShouldInit(cfg *config.BaseConfig) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ElasticsearchService ¶
type ElasticsearchService struct{}
ElasticsearchService Elasticsearch服务
func (*ElasticsearchService) Close ¶
func (s *ElasticsearchService) Close(ctx context.Context) error
Close 关闭Elasticsearch连接
func (*ElasticsearchService) Dependencies ¶
func (s *ElasticsearchService) Dependencies() []string
Dependencies 返回依赖
func (*ElasticsearchService) HealthCheck ¶
func (s *ElasticsearchService) HealthCheck(ctx context.Context) error
HealthCheck 健康检查
func (*ElasticsearchService) Init ¶
func (s *ElasticsearchService) Init(ctx context.Context) error
Init 初始化Elasticsearch
func (*ElasticsearchService) Priority ¶
func (s *ElasticsearchService) Priority() int
Priority 返回初始化优先级
func (*ElasticsearchService) ShouldInit ¶
func (s *ElasticsearchService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 根据配置判断是否需要初始化
type EtcdService ¶
type EtcdService struct{}
EtcdService Etcd服务
func (*EtcdService) HealthCheck ¶
func (s *EtcdService) HealthCheck(ctx context.Context) error
HealthCheck 健康检查
func (*EtcdService) ShouldInit ¶
func (s *EtcdService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 根据配置判断是否需要初始化
type LoggerService ¶
type LoggerService struct{}
LoggerService 日志服务
func (*LoggerService) Close ¶
func (s *LoggerService) Close(ctx context.Context) error
Close 关闭日志(通常不需要)
func (*LoggerService) Dependencies ¶
func (s *LoggerService) Dependencies() []string
Dependencies 返回依赖(日志无依赖)
func (*LoggerService) ShouldInit ¶
func (s *LoggerService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 日志总是需要初始化
type MySQLService ¶
type MySQLService struct{}
MySQLService MySQL数据库服务
func (*MySQLService) Close ¶
func (s *MySQLService) Close(ctx context.Context) error
Close 关闭数据库连接,显式释放所有 sql.DB 底层连接资源
func (*MySQLService) Dependencies ¶
func (s *MySQLService) Dependencies() []string
Dependencies 返回依赖
func (*MySQLService) HealthCheck ¶
func (s *MySQLService) HealthCheck(ctx context.Context) error
HealthCheck 健康检查
func (*MySQLService) ShouldInit ¶
func (s *MySQLService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 根据配置判断是否需要初始化
type RabbitMQService ¶
type RabbitMQService struct {
// contains filtered or unexported fields
}
RabbitMQService RabbitMQ消息队列服务
func NewRabbitMQService ¶
func NewRabbitMQService(consumerList, producerList []*config.MessageQueue) *RabbitMQService
NewRabbitMQService 创建RabbitMQ服务
func (*RabbitMQService) Close ¶
func (s *RabbitMQService) Close(ctx context.Context) error
Close 关闭RabbitMQ连接
func (*RabbitMQService) Dependencies ¶
func (s *RabbitMQService) Dependencies() []string
Dependencies 返回依赖
func (*RabbitMQService) Init ¶
func (s *RabbitMQService) Init(ctx context.Context) error
Init 初始化RabbitMQ
func (*RabbitMQService) SetConsumerList ¶
func (s *RabbitMQService) SetConsumerList(list []*config.MessageQueue)
SetConsumerList 设置消费者列表
func (*RabbitMQService) SetProducerList ¶
func (s *RabbitMQService) SetProducerList(list []*config.MessageQueue)
SetProducerList 设置生产者列表
func (*RabbitMQService) ShouldInit ¶
func (s *RabbitMQService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 根据配置判断是否需要初始化
type RedisService ¶
type RedisService struct{}
RedisService Redis服务
func (*RedisService) Close ¶
func (s *RedisService) Close(ctx context.Context) error
Close 关闭Redis连接
func (*RedisService) Dependencies ¶
func (s *RedisService) Dependencies() []string
Dependencies 返回依赖
func (*RedisService) HealthCheck ¶
func (s *RedisService) HealthCheck(ctx context.Context) error
HealthCheck 健康检查
func (*RedisService) ShouldInit ¶
func (s *RedisService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 根据配置判断是否需要初始化
type ScheduleService ¶
type ScheduleService struct {
// contains filtered or unexported fields
}
ScheduleService 定时任务服务
func NewScheduleService ¶
func NewScheduleService(scheduleList []config.ScheduleInfo) *ScheduleService
NewScheduleService 创建定时任务服务
func (*ScheduleService) Close ¶
func (s *ScheduleService) Close(ctx context.Context) error
Close 关闭定时任务
func (*ScheduleService) Dependencies ¶
func (s *ScheduleService) Dependencies() []string
Dependencies 返回依赖
func (*ScheduleService) Init ¶
func (s *ScheduleService) Init(ctx context.Context) error
Init 初始化定时任务
func (*ScheduleService) Priority ¶
func (s *ScheduleService) Priority() int
Priority 返回初始化优先级(最后初始化)
func (*ScheduleService) SetScheduleList ¶
func (s *ScheduleService) SetScheduleList(list []config.ScheduleInfo)
SetScheduleList 设置定时任务列表
func (*ScheduleService) ShouldInit ¶
func (s *ScheduleService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 根据配置判断是否需要初始化
type TracingService ¶
type TracingService struct{}
TracingService 链路追踪服务 实现了 core.Service 接口,用于管理 OpenTelemetry 追踪器的生命周期
func (*TracingService) Close ¶
func (s *TracingService) Close(ctx context.Context) error
Close 关闭链路追踪 确保所有待发送的追踪数据被刷新到采集器
func (*TracingService) Dependencies ¶
func (s *TracingService) Dependencies() []string
Dependencies 返回依赖 追踪服务依赖日志服务,用于记录初始化状态
func (*TracingService) Priority ¶
func (s *TracingService) Priority() int
Priority 返回初始化优先级 追踪服务需要在日志之后、其他服务之前初始化 这样可以确保其他服务的初始化过程也能被追踪
func (*TracingService) ShouldInit ¶
func (s *TracingService) ShouldInit(cfg *config.BaseConfig) bool
ShouldInit 判断是否需要初始化 只有在配置了链路追踪且启用时才初始化