Documentation
¶
Index ¶
- func Get[T any](c *DependencyContainer) (T, bool)
- func Has[T any](c *DependencyContainer) bool
- func MustGet[T any](c *DependencyContainer) T
- func Register[T any](c *DependencyContainer, instance T)
- func SetFieldByPath(registry *DefaultConfigRegistry, module, fieldPath, value string) error
- func ValidateConfig(cfg ConfigRegistry) error
- type App
- func (a *App) GetClickHouse() *clickhouse.ClickHouseClient
- func (a *App) GetDependencies() DependencyList
- func (a *App) GetDependencyContainer() *DependencyContainer
- func (a *App) GetElasticsearch() *elasticsearch.ElasticsearchClient
- func (a *App) GetEmail() *email.EmailClient
- func (a *App) GetMessageQueue() *messagequeue.Client
- func (a *App) GetModuleRegistry() *ModuleRegistry
- func (a *App) GetMongoDB() *mongodb.MongoDBClient
- func (a *App) GetMySQL() *gorm.DB
- func (a *App) GetOSS() *oss.StoreFactory
- func (a *App) GetPostgreSQL() *gorm.DB
- func (a *App) GetRedis() *redis.Client
- func (a *App) GetRouter() *gin.Engine
- func (a *App) GetServiceRegistry() *ServiceRegistry
- func (a *App) GetXxlJob() xxljob.Executor
- func (a *App) Shutdown() error
- func (a *App) StartHTTPServer() error
- func (a *App) StartRPCServer() (*Server, error)
- type AppBuilder
- func (b *AppBuilder) Build() (*App, error)
- func (b *AppBuilder) RegisterDependency(instance interface{})
- func (b *AppBuilder) WithClickHouse() *AppBuilder
- func (b *AppBuilder) WithConfigCenter(cfg *configcenter.Config, opts ...ConfigCenterOption) *AppBuilder
- func (b *AppBuilder) WithCron() *AppBuilder
- func (b *AppBuilder) WithDependency(name string, depType DependencyType, init DependencyInitializer) *AppBuilder
- func (b *AppBuilder) WithDistributedLock() *AppBuilder
- func (b *AppBuilder) WithElasticsearch() *AppBuilder
- func (b *AppBuilder) WithEmail() *AppBuilder
- func (b *AppBuilder) WithHTTP(configDir string, routeSetupFunc RouteSetupFunc) *AppBuilder
- func (b *AppBuilder) WithLocalCache() *AppBuilder
- func (b *AppBuilder) WithMessageQueue() *AppBuilder
- func (b *AppBuilder) WithModules(modules ...Module) *AppBuilder
- func (b *AppBuilder) WithMongoDB() *AppBuilder
- func (b *AppBuilder) WithMySQL() *AppBuilder
- func (b *AppBuilder) WithOSS() *AppBuilder
- func (b *AppBuilder) WithPostgreSQL() *AppBuilder
- func (b *AppBuilder) WithRateLimit() *AppBuilder
- func (b *AppBuilder) WithRedis() *AppBuilder
- func (b *AppBuilder) WithServices() *AppBuilder
- func (b *AppBuilder) WithWebSocket() *AppBuilder
- func (b *AppBuilder) WithXxlJob(middlewares ...xxljob.Middleware) *AppBuilder
- type ConfigCenterOption
- type ConfigRegistry
- type ConfigValidator
- type DefaultConfigRegistry
- func (r *DefaultConfigRegistry) GetClickHouse() (*clickhouse.Config, error)
- func (r *DefaultConfigRegistry) GetConfigCenter() (*configcenter.Config, error)
- func (r *DefaultConfigRegistry) GetElasticsearch() (*elasticsearch.Config, error)
- func (r *DefaultConfigRegistry) GetEmail() (*email.Config, error)
- func (r *DefaultConfigRegistry) GetLog() (*log.Config, error)
- func (r *DefaultConfigRegistry) GetMessageQueue() (*messagequeue.Config, error)
- func (r *DefaultConfigRegistry) GetMongoDB() (*mongodb.Config, error)
- func (r *DefaultConfigRegistry) GetMySQL() (*db.MySQLConfig, error)
- func (r *DefaultConfigRegistry) GetOSS() (*oss.Config, error)
- func (r *DefaultConfigRegistry) GetPostgreSQL() (*db.PostgreSQLConfig, error)
- func (r *DefaultConfigRegistry) GetRedis() (*db.RedisConfig, error)
- func (r *DefaultConfigRegistry) GetServer() (*ServerConfig, error)
- func (r *DefaultConfigRegistry) GetServices() (map[string]ServiceConfig, error)
- func (r *DefaultConfigRegistry) GetWebSocket() (*websocket.Config, error)
- func (r *DefaultConfigRegistry) GetXxlJob() (*xxljob.Config, error)
- func (r *DefaultConfigRegistry) HasClickHouse() bool
- func (r *DefaultConfigRegistry) HasConfigCenter() bool
- func (r *DefaultConfigRegistry) HasEmail() bool
- func (r *DefaultConfigRegistry) HasLog() bool
- func (r *DefaultConfigRegistry) HasMessageQueue() bool
- func (r *DefaultConfigRegistry) HasMongoDB() bool
- func (r *DefaultConfigRegistry) HasMySQL() bool
- func (r *DefaultConfigRegistry) HasOSS() bool
- func (r *DefaultConfigRegistry) HasPostgreSQL() bool
- func (r *DefaultConfigRegistry) HasRedis() bool
- func (r *DefaultConfigRegistry) HasServer() bool
- func (r *DefaultConfigRegistry) HasServices() bool
- func (r *DefaultConfigRegistry) HasWebSocket() bool
- func (r *DefaultConfigRegistry) HasXxlJob() bool
- func (r *DefaultConfigRegistry) MustGetClickHouse() *clickhouse.Config
- func (r *DefaultConfigRegistry) MustGetConfigCenter() *configcenter.Config
- func (r *DefaultConfigRegistry) MustGetEmail() *email.Config
- func (r *DefaultConfigRegistry) MustGetLog() *log.Config
- func (r *DefaultConfigRegistry) MustGetMessageQueue() *messagequeue.Config
- func (r *DefaultConfigRegistry) MustGetMongoDB() *mongodb.Config
- func (r *DefaultConfigRegistry) MustGetMySQL() *db.MySQLConfig
- func (r *DefaultConfigRegistry) MustGetOSS() *oss.Config
- func (r *DefaultConfigRegistry) MustGetPostgreSQL() *db.PostgreSQLConfig
- func (r *DefaultConfigRegistry) MustGetRedis() *db.RedisConfig
- func (r *DefaultConfigRegistry) MustGetServer() *ServerConfig
- func (r *DefaultConfigRegistry) MustGetServices() map[string]ServiceConfig
- func (r *DefaultConfigRegistry) MustGetWebSocket() *websocket.Config
- func (r *DefaultConfigRegistry) MustGetXxlJob() *xxljob.Config
- type Dependency
- type DependencyContainer
- type DependencyInitializer
- type DependencyList
- type DependencyType
- type Duration
- type GRPCConfig
- type GRPCServiceRegister
- type GRPCSizeLimitConfig
- type GatewayServiceRegister
- type HTTPConfig
- type Lifecycle
- type Module
- type ModuleRegistry
- type RouteSetupFunc
- type Server
- type ServerConfig
- type ServiceConfig
- type ServiceRegistration
- type ServiceRegistry
- func (r *ServiceRegistry) GetServices() []ServiceRegistration
- func (r *ServiceRegistry) Register(reg ServiceRegistration)
- func (r *ServiceRegistry) RegisterAll(regs ...ServiceRegistration)
- func (r *ServiceRegistry) RegisterToGRPCServer(server *grpc.Server)
- func (r *ServiceRegistry) RegisterToGateway(ctx context.Context, gwHandler interface{ ... }, grpcAddr string, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
func Get[T any](c *DependencyContainer) (T, bool)
Get 获取依赖实例(类型安全) 使用示例: service, ok := Get[MyService](container)
func Has ¶
func Has[T any](c *DependencyContainer) bool
Has 检查依赖是否存在 使用示例: if Has[MyService](container) { ... }
func MustGet ¶
func MustGet[T any](c *DependencyContainer) T
MustGet 获取依赖实例,如果不存在则 panic 使用示例: service := MustGet[MyService](container)
func Register ¶
func Register[T any](c *DependencyContainer, instance T)
Register 注册依赖实例(类型安全) 使用示例: Register(container, myService)
func SetFieldByPath ¶
func SetFieldByPath(registry *DefaultConfigRegistry, module, fieldPath, value string) error
SetFieldByPath 根据路径设置字段值(通用实现) 这是通用的字段设置逻辑,可以被所有服务复用
Types ¶
type App ¶
type App struct {
// 服务名(从配置中读取)
ServiceName string
// 配置(接口类型)
Config ConfigRegistry
// 基础设施依赖
MySQL *gorm.DB
PostgreSQL *gorm.DB
Redis *redis.Client
MessageQueue *messagequeue.Client
ClickHouse *clickhouse.ClickHouseClient
Elasticsearch *elasticsearch.ElasticsearchClient
Email *email.EmailClient
XxlJob xxljob.Executor
MongoDB *mongodb.MongoDBClient
OSS *oss.StoreFactory
// HTTP 服务器相关(用于网关或 HTTP 服务)
Router *gin.Engine
Handler interface{} // gateway.GatewayHandler,使用 interface{} 避免循环依赖
HTTPServer *http.Server
// 可热更新的组件(限流器、熔断器等)
RateLimitManager ratelimit.RateLimitManager // 业务限流管理器
// contains filtered or unexported fields
}
App 应用主结构体,显式声明所有依赖
func (*App) GetClickHouse ¶
func (a *App) GetClickHouse() *clickhouse.ClickHouseClient
GetClickHouse 获取 ClickHouse 客户端连接
func (*App) GetDependencyContainer ¶
func (a *App) GetDependencyContainer() *DependencyContainer
GetDependencyContainer 获取依赖容器
func (*App) GetElasticsearch ¶
func (a *App) GetElasticsearch() *elasticsearch.ElasticsearchClient
GetElasticsearch 获取 Elasticsearch 客户端连接
func (*App) GetMessageQueue ¶
func (a *App) GetMessageQueue() *messagequeue.Client
GetMessageQueue 获取消息队列客户端
func (*App) GetModuleRegistry ¶
func (a *App) GetModuleRegistry() *ModuleRegistry
GetModuleRegistry 获取模块注册表
func (*App) GetMongoDB ¶
func (a *App) GetMongoDB() *mongodb.MongoDBClient
GetMongoDB 获取 MongoDB 客户端连接
func (*App) GetPostgreSQL ¶
GetPostgreSQL 获取 PostgreSQL 数据库连接
func (*App) GetServiceRegistry ¶
func (a *App) GetServiceRegistry() *ServiceRegistry
GetServiceRegistry 获取服务注册表
func (*App) StartRPCServer ¶
StartRPCServer 启动 gRPC 服务器(仅 RPC,不启动 HTTP)
type AppBuilder ¶
type AppBuilder struct {
// contains filtered or unexported fields
}
AppBuilder App 构建器,提供链式初始化方法
func (*AppBuilder) RegisterDependency ¶
func (b *AppBuilder) RegisterDependency(instance interface{})
RegisterDependency 注册依赖实例 在 WithDependency 的初始化函数中调用此方法来注册依赖 使用示例: builder.RegisterDependency(myService) 注意:为了类型安全,推荐使用 app.Register(container, instance) 函数
func (*AppBuilder) WithClickHouse ¶
func (b *AppBuilder) WithClickHouse() *AppBuilder
WithClickHouse 初始化 ClickHouse 连接
func (*AppBuilder) WithConfigCenter ¶
func (b *AppBuilder) WithConfigCenter(cfg *configcenter.Config, opts ...ConfigCenterOption) *AppBuilder
WithConfigCenter 初始化配置中心和热加载系统 cfg: 配置中心配置(从配置注册表中获取,如果为 nil 或 type 为 "none" 则跳过初始化) opts: 配置选项(字段设置器、重载器等) 注意:如果需要在重载器中访问 App 中的组件(如 RateLimitManager), 可以使用 WithReloaders 并提供获取组件的函数
func (*AppBuilder) WithDependency ¶
func (b *AppBuilder) WithDependency(name string, depType DependencyType, init DependencyInitializer) *AppBuilder
WithDependency 注册并初始化自定义依赖(类型安全) depType: 依赖类型(用于依赖清单) init: 依赖初始化函数,返回依赖实例 使用示例:
builder.WithDependency("myService", app.DependencyType("custom"), func(b *app.AppBuilder) error {
service := NewMyService()
b.RegisterDependency(service) // 类型安全注册
return nil
})
func (*AppBuilder) WithDistributedLock ¶
func (b *AppBuilder) WithDistributedLock() *AppBuilder
WithDistributedLock 初始化分布式锁(需要 Redis)
func (*AppBuilder) WithElasticsearch ¶
func (b *AppBuilder) WithElasticsearch() *AppBuilder
WithElasticsearch 初始化 Elasticsearch 连接
func (*AppBuilder) WithHTTP ¶
func (b *AppBuilder) WithHTTP(configDir string, routeSetupFunc RouteSetupFunc) *AppBuilder
WithHTTP 初始化 HTTP 服务器相关组件(限流器、中间件、Gin 路由等) configDir: 配置目录路径(用于加载限流规则配置文件) routeSetupFunc: 路由设置回调函数(可选)
func (*AppBuilder) WithLocalCache ¶
func (b *AppBuilder) WithLocalCache() *AppBuilder
WithLocalCache 初始化本地缓存
func (*AppBuilder) WithMessageQueue ¶
func (b *AppBuilder) WithMessageQueue() *AppBuilder
WithMessageQueue 统一初始化消息队列(根据配置自动选择类型)
func (*AppBuilder) WithModules ¶
func (b *AppBuilder) WithModules(modules ...Module) *AppBuilder
WithModules 注册业务模块 使用示例: builder.WithModules(apiModule.NewApiModule())
func (*AppBuilder) WithMongoDB ¶
func (b *AppBuilder) WithMongoDB() *AppBuilder
WithMongoDB 初始化 MongoDB 连接
func (*AppBuilder) WithMySQL ¶
func (b *AppBuilder) WithMySQL() *AppBuilder
WithMySQL 初始化 MySQL 数据库连接
func (*AppBuilder) WithOSS ¶
func (b *AppBuilder) WithOSS() *AppBuilder
WithOSS 初始化对象存储连接(支持 AWS S3、阿里云 OSS、腾讯云 COS、MinIO)
func (*AppBuilder) WithPostgreSQL ¶
func (b *AppBuilder) WithPostgreSQL() *AppBuilder
WithPostgreSQL 初始化 PostgreSQL 数据库连接
func (*AppBuilder) WithRateLimit ¶
func (b *AppBuilder) WithRateLimit() *AppBuilder
WithRateLimit 初始化分布式限流(需要 Redis)
func (*AppBuilder) WithServices ¶
func (b *AppBuilder) WithServices() *AppBuilder
WithServices 初始化所有模块和服务 这会初始化所有已注册的模块,并将它们的服务注册到服务注册表
func (*AppBuilder) WithWebSocket ¶
func (b *AppBuilder) WithWebSocket() *AppBuilder
WithWebSocket 初始化 WebSocket 服务器
func (*AppBuilder) WithXxlJob ¶
func (b *AppBuilder) WithXxlJob(middlewares ...xxljob.Middleware) *AppBuilder
WithXxlJob 初始化 XXL-JOB 执行器 middlewares: 可选的中间件列表,按顺序应用 使用示例:
WithXxlJob() // 无中间件 WithXxlJob(xxljob.RecoveryMiddleware(), xxljob.TimeoutMiddleware(30*time.Second))
type ConfigCenterOption ¶
type ConfigCenterOption func(*configCenterOptions)
ConfigCenterOption 配置中心选项函数类型
func WithFieldSetter ¶
func WithFieldSetter(setter func(module, fieldPath, value string) error, prefixes []string) ConfigCenterOption
WithFieldSetter 设置字段设置器(用于系统配置热加载)
func WithReloaderFactories ¶
func WithReloaderFactories(factories ...func(*App) []hotreload.Reloader) ConfigCenterOption
WithReloaderFactories 设置重载器工厂函数(用于延迟创建重载器) 这些工厂函数会在 App 构建后调用,可以访问 App 中的组件
func WithReloaders ¶
func WithReloaders(reloaders ...hotreload.Reloader) ConfigCenterOption
WithReloaders 设置配置重载器(用于自定义配置热加载)
type ConfigRegistry ¶
type ConfigRegistry interface {
GetMySQL() (*db.MySQLConfig, error)
GetRedis() (*db.RedisConfig, error)
GetClickHouse() (*clickhouse.Config, error)
GetEmail() (*email.Config, error)
GetServer() (*ServerConfig, error)
GetLog() (*log.Config, error)
GetXxlJob() (*xxljob.Config, error)
GetElasticsearch() (*elasticsearch.Config, error)
GetMongoDB() (*mongodb.Config, error)
GetPostgreSQL() (*db.PostgreSQLConfig, error)
GetOSS() (*oss.Config, error)
GetWebSocket() (*websocket.Config, error)
GetMessageQueue() (*messagequeue.Config, error)
GetConfigCenter() (*configcenter.Config, error)
GetServices() (map[string]ServiceConfig, error)
}
ConfigRegistry 配置注册表接口,所有服务的配置注册表都应实现此接口
type ConfigValidator ¶
type ConfigValidator struct {
// contains filtered or unexported fields
}
ConfigValidator 配置验证器
func (*ConfigValidator) Validate ¶
func (v *ConfigValidator) Validate(cfg ConfigRegistry) error
Validate 验证配置注册表
type DefaultConfigRegistry ¶
type DefaultConfigRegistry struct {
Mysql *db.MySQLConfig `yaml:"mysql"`
Redis *db.RedisConfig `yaml:"redis"`
ClickHouse *clickhouse.Config `yaml:"clickhouse"`
Email *email.Config `yaml:"email"`
Server *ServerConfig `yaml:"server"`
Log *log.Config `yaml:"log"`
XxlJob *xxljob.Config `yaml:"xxl_job"`
Elasticsearch *elasticsearch.Config `yaml:"elasticsearch"`
MongoDB *mongodb.Config `yaml:"mongodb"`
PostgreSQL *db.PostgreSQLConfig `yaml:"postgresql"`
OSS *oss.Config `yaml:"oss"`
WebSocket *websocket.Config `yaml:"websocket"`
MessageQueue *messagequeue.Config `yaml:"message_queue"`
ConfigCenter *configcenter.Config `yaml:"config_center"`
Services map[string]ServiceConfig `yaml:"services"` // RPC 服务地址配置
}
DefaultConfigRegistry 配置注册表,管理所有配置模块 实现 ConfigRegistry 接口 这是通用的实现,可以被多个服务复用
func (*DefaultConfigRegistry) GetClickHouse ¶
func (r *DefaultConfigRegistry) GetClickHouse() (*clickhouse.Config, error)
GetClickHouse 获取 ClickHouse 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetConfigCenter ¶
func (r *DefaultConfigRegistry) GetConfigCenter() (*configcenter.Config, error)
GetConfigCenter 获取配置中心配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetElasticsearch ¶
func (r *DefaultConfigRegistry) GetElasticsearch() (*elasticsearch.Config, error)
GetElasticsearch 获取 Elasticsearch 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetEmail ¶
func (r *DefaultConfigRegistry) GetEmail() (*email.Config, error)
GetEmail 获取邮件配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetLog ¶
func (r *DefaultConfigRegistry) GetLog() (*log.Config, error)
GetLog 获取日志配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetMessageQueue ¶
func (r *DefaultConfigRegistry) GetMessageQueue() (*messagequeue.Config, error)
GetMessageQueue 获取消息队列配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetMongoDB ¶
func (r *DefaultConfigRegistry) GetMongoDB() (*mongodb.Config, error)
GetMongoDB 获取 MongoDB 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetMySQL ¶
func (r *DefaultConfigRegistry) GetMySQL() (*db.MySQLConfig, error)
GetMySQL 获取 MySQL 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetOSS ¶
func (r *DefaultConfigRegistry) GetOSS() (*oss.Config, error)
GetOSS 获取对象存储配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetPostgreSQL ¶
func (r *DefaultConfigRegistry) GetPostgreSQL() (*db.PostgreSQLConfig, error)
GetPostgreSQL 获取 PostgreSQL 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetRedis ¶
func (r *DefaultConfigRegistry) GetRedis() (*db.RedisConfig, error)
GetRedis 获取 Redis 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetServer ¶
func (r *DefaultConfigRegistry) GetServer() (*ServerConfig, error)
GetServer 获取服务器配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetServices ¶
func (r *DefaultConfigRegistry) GetServices() (map[string]ServiceConfig, error)
GetServices 获取 RPC 服务地址配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetWebSocket ¶
func (r *DefaultConfigRegistry) GetWebSocket() (*websocket.Config, error)
GetWebSocket 获取 WebSocket 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) GetXxlJob ¶
func (r *DefaultConfigRegistry) GetXxlJob() (*xxljob.Config, error)
GetXxlJob 获取 XXL-JOB 配置(实现 ConfigRegistry 接口)
func (*DefaultConfigRegistry) HasClickHouse ¶
func (r *DefaultConfigRegistry) HasClickHouse() bool
HasClickHouse 检查是否已加载 ClickHouse 配置
func (*DefaultConfigRegistry) HasConfigCenter ¶
func (r *DefaultConfigRegistry) HasConfigCenter() bool
HasConfigCenter 检查是否已加载配置中心配置
func (*DefaultConfigRegistry) HasEmail ¶
func (r *DefaultConfigRegistry) HasEmail() bool
HasEmail 检查是否已加载邮件配置
func (*DefaultConfigRegistry) HasLog ¶
func (r *DefaultConfigRegistry) HasLog() bool
HasLog 检查是否已加载日志配置
func (*DefaultConfigRegistry) HasMessageQueue ¶
func (r *DefaultConfigRegistry) HasMessageQueue() bool
HasMessageQueue 检查是否已加载消息队列配置
func (*DefaultConfigRegistry) HasMongoDB ¶
func (r *DefaultConfigRegistry) HasMongoDB() bool
HasMongoDB 检查是否已加载 MongoDB 配置
func (*DefaultConfigRegistry) HasMySQL ¶
func (r *DefaultConfigRegistry) HasMySQL() bool
HasMySQL 检查是否已加载 MySQL 配置
func (*DefaultConfigRegistry) HasOSS ¶
func (r *DefaultConfigRegistry) HasOSS() bool
HasOSS 检查是否已加载对象存储配置
func (*DefaultConfigRegistry) HasPostgreSQL ¶
func (r *DefaultConfigRegistry) HasPostgreSQL() bool
HasPostgreSQL 检查是否已加载 PostgreSQL 配置
func (*DefaultConfigRegistry) HasRedis ¶
func (r *DefaultConfigRegistry) HasRedis() bool
HasRedis 检查是否已加载 Redis 配置
func (*DefaultConfigRegistry) HasServer ¶
func (r *DefaultConfigRegistry) HasServer() bool
HasServer 检查是否已加载服务器配置
func (*DefaultConfigRegistry) HasServices ¶
func (r *DefaultConfigRegistry) HasServices() bool
HasServices 检查是否已加载服务地址配置
func (*DefaultConfigRegistry) HasWebSocket ¶
func (r *DefaultConfigRegistry) HasWebSocket() bool
HasWebSocket 检查是否已加载 WebSocket 配置
func (*DefaultConfigRegistry) HasXxlJob ¶
func (r *DefaultConfigRegistry) HasXxlJob() bool
HasXxlJob 检查是否已加载 XXL-JOB 配置
func (*DefaultConfigRegistry) MustGetClickHouse ¶
func (r *DefaultConfigRegistry) MustGetClickHouse() *clickhouse.Config
MustGetClickHouse 获取 ClickHouse 配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetConfigCenter ¶
func (r *DefaultConfigRegistry) MustGetConfigCenter() *configcenter.Config
MustGetConfigCenter 获取配置中心配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetEmail ¶
func (r *DefaultConfigRegistry) MustGetEmail() *email.Config
MustGetEmail 获取邮件配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetLog ¶
func (r *DefaultConfigRegistry) MustGetLog() *log.Config
MustGetLog 获取日志配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetMessageQueue ¶
func (r *DefaultConfigRegistry) MustGetMessageQueue() *messagequeue.Config
MustGetMessageQueue 获取消息队列配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetMongoDB ¶
func (r *DefaultConfigRegistry) MustGetMongoDB() *mongodb.Config
MustGetMongoDB 获取 MongoDB 配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetMySQL ¶
func (r *DefaultConfigRegistry) MustGetMySQL() *db.MySQLConfig
MustGetMySQL 获取 MySQL 配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetOSS ¶
func (r *DefaultConfigRegistry) MustGetOSS() *oss.Config
MustGetOSS 获取对象存储配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetPostgreSQL ¶
func (r *DefaultConfigRegistry) MustGetPostgreSQL() *db.PostgreSQLConfig
MustGetPostgreSQL 获取 PostgreSQL 配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetRedis ¶
func (r *DefaultConfigRegistry) MustGetRedis() *db.RedisConfig
MustGetRedis 获取 Redis 配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetServer ¶
func (r *DefaultConfigRegistry) MustGetServer() *ServerConfig
MustGetServer 获取服务器配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetServices ¶
func (r *DefaultConfigRegistry) MustGetServices() map[string]ServiceConfig
MustGetServices 获取 RPC 服务地址配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetWebSocket ¶
func (r *DefaultConfigRegistry) MustGetWebSocket() *websocket.Config
MustGetWebSocket 获取 WebSocket 配置,如果不存在则 panic
func (*DefaultConfigRegistry) MustGetXxlJob ¶
func (r *DefaultConfigRegistry) MustGetXxlJob() *xxljob.Config
MustGetXxlJob 获取 XXL-JOB 配置,如果不存在则 panic
type Dependency ¶
type Dependency struct {
Type DependencyType `json:"type"`
Name string `json:"name"`
Initialized bool `json:"initialized"`
Error error `json:"error,omitempty"`
}
Dependency 依赖信息
type DependencyContainer ¶
type DependencyContainer struct {
// contains filtered or unexported fields
}
DependencyContainer 类型安全的依赖容器 通过类型来注册和获取依赖,提供编译时类型检查
func NewDependencyContainer ¶
func NewDependencyContainer() *DependencyContainer
NewDependencyContainer 创建新的依赖容器
func (*DependencyContainer) GetAll ¶
func (c *DependencyContainer) GetAll() []reflect.Type
GetAll 获取所有已注册的依赖类型
type DependencyInitializer ¶
type DependencyInitializer func(builder *AppBuilder) error
DependencyInitializer 依赖初始化器函数类型 用于插件化依赖初始化
type DependencyList ¶
type DependencyList []Dependency
DependencyList 依赖清单
func (DependencyList) GetDependency ¶
func (dl DependencyList) GetDependency(depType DependencyType) *Dependency
GetDependency 获取指定类型的依赖
func (DependencyList) HasDependency ¶
func (dl DependencyList) HasDependency(depType DependencyType) bool
HasDependency 检查是否包含指定类型的依赖
type DependencyType ¶
type DependencyType string
DependencyType 依赖类型
const ( // DependencyMySQL MySQL 数据库依赖 DependencyMySQL DependencyType = "mysql" // DependencyRedis Redis 缓存依赖 DependencyRedis DependencyType = "redis" // DependencyKafka Kafka 消息队列依赖 DependencyKafka DependencyType = "kafka" // DependencyMQ MQ 消息队列依赖 DependencyMQ DependencyType = "mq" // DependencyClickHouse ClickHouse 数据库依赖 DependencyClickHouse DependencyType = "clickhouse" // DependencyEmail 邮件服务依赖 DependencyEmail DependencyType = "email" // DependencyElasticsearch Elasticsearch 搜索依赖 DependencyElasticsearch DependencyType = "elasticsearch" // DependencyLog 日志依赖 DependencyLog DependencyType = "log" // DependencyXxlJob XXL-JOB 任务调度依赖 DependencyXxlJob DependencyType = "xxl_job" // DependencyMongoDB MongoDB 数据库依赖 DependencyMongoDB DependencyType = "mongodb" // DependencyPostgreSQL PostgreSQL 数据库依赖 DependencyPostgreSQL DependencyType = "postgresql" // DependencyOSS 对象存储依赖(支持 AWS S3、阿里云 OSS、腾讯云 COS、MinIO) DependencyOSS DependencyType = "oss" // DependencyConfigCenter 配置中心依赖(支持 Apollo、Nacos、Consul) DependencyConfigCenter DependencyType = "config_center" // DependencyWebSocket WebSocket 服务器依赖 DependencyWebSocket DependencyType = "websocket" // DependencyDistributedLock 分布式锁依赖 DependencyDistributedLock DependencyType = "distributed_lock" // DependencyLocalCache 本地缓存依赖 DependencyLocalCache DependencyType = "local_cache" // DependencyCron Cron 定时任务依赖 DependencyCron DependencyType = "cron" // DependencyRateLimit 分布式限流依赖 DependencyRateLimit DependencyType = "rate_limit" )
type GRPCConfig ¶
type GRPCConfig struct {
Host string `yaml:"host" env:"GRPC_HOST" default:"0.0.0.0"`
Port string `yaml:"port" env:"GRPC_PORT" default:"50051"`
SizeLimit GRPCSizeLimitConfig `yaml:"size_limit"`
}
GRPCConfig gRPC 服务器配置
func (*GRPCConfig) Address ¶
func (c *GRPCConfig) Address() string
Address 返回 gRPC 服务器地址(带冒号前缀,用于 net.Listen)
func (*GRPCConfig) FullAddress ¶
func (c *GRPCConfig) FullAddress() string
FullAddress 返回完整的 gRPC 服务器地址
type GRPCServiceRegister ¶
GRPCServiceRegister gRPC 服务注册函数类型 用于注册 gRPC 服务到 gRPC 服务器
type GRPCSizeLimitConfig ¶
type GRPCSizeLimitConfig struct {
Enabled bool `yaml:"enabled" env:"GRPC_SIZE_LIMIT_ENABLED" default:"true"`
MaxRecvMsgSize int `yaml:"max_recv_msg_size" env:"GRPC_MAX_RECV_MSG_SIZE" default:"4194304"` // 默认 4MB
MaxSendMsgSize int `yaml:"max_send_msg_size" env:"GRPC_MAX_SEND_MSG_SIZE" default:"4194304"` // 默认 4MB
}
GRPCSizeLimitConfig gRPC 消息大小限制配置
type GatewayServiceRegister ¶
type GatewayServiceRegister func(ctx context.Context, mux *runtime.ServeMux, grpcAddr string, opts []grpc.DialOption) error
GatewayServiceRegister 网关服务注册函数类型 用于注册 gRPC 服务到 HTTP 网关 函数签名与 gateway.RegisterService 兼容
type HTTPConfig ¶
type HTTPConfig struct {
Host string `yaml:"host" env:"HTTP_HOST" default:"0.0.0.0"`
Port string `yaml:"port" env:"HTTP_PORT" default:"8080"`
}
HTTPConfig HTTP 服务器配置
func (*HTTPConfig) Address ¶
func (c *HTTPConfig) Address() string
Address 返回 HTTP 服务器地址(带冒号前缀,用于 net.Listen)
func (*HTTPConfig) FullAddress ¶
func (c *HTTPConfig) FullAddress() string
FullAddress 返回完整的 HTTP 服务器地址
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle 生命周期管理器
func (*Lifecycle) RegisterShutdown ¶
RegisterShutdown 注册关闭函数
type Module ¶
type Module interface {
// Name 返回模块名称
Name() string
// Initialize 初始化模块,接收 App 对象作为依赖注入
// 返回模块注册的服务列表
// 通过 app 对象可以访问所有依赖:Config, MySQL, Redis, Kafka, GetDependencyContainer() 等
Initialize(app *App) ([]ServiceRegistration, error)
// Shutdown 关闭模块,清理资源
Shutdown() error
}
Module 模块接口,定义业务模块的标准接口 每个业务模块(如 api_module)都应该实现此接口
type ModuleRegistry ¶
type ModuleRegistry struct {
// contains filtered or unexported fields
}
ModuleRegistry 模块注册表
func (*ModuleRegistry) GetModules ¶
func (r *ModuleRegistry) GetModules() []Module
GetModules 获取所有注册的模块
func (*ModuleRegistry) InitializeAll ¶
func (r *ModuleRegistry) InitializeAll(app *App) ([]ServiceRegistration, error)
InitializeAll 初始化所有模块,返回所有服务的注册信息
func (*ModuleRegistry) RegisterAll ¶
func (r *ModuleRegistry) RegisterAll(modules ...Module)
RegisterAll 批量注册模块
func (*ModuleRegistry) ShutdownAll ¶
func (r *ModuleRegistry) ShutdownAll() error
ShutdownAll 关闭所有模块
type RouteSetupFunc ¶
RouteSetupFunc 路由和服务注册回调函数类型 router: 已配置好中间件的 Gin 路由引擎 handler: 网关处理器,用于注册 gRPC 服务
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 服务器结构体
func (*Server) GracefulStopWithTimeout ¶
GracefulStopWithTimeout 带超时的优雅停止服务器
type ServerConfig ¶
type ServerConfig struct {
ServiceName string `yaml:"service_name" env:"SERVICE_NAME" required:"true"`
HTTP *HTTPConfig `yaml:"http,omitempty"` // 可选,用于 HTTP 服务
GRPC GRPCConfig `yaml:"grpc"` // 可选,用于 RPC 服务
Features pkgConfig.FeaturesConfig `yaml:"features"` // 统一使用 FeaturesConfig 支持网关和 RPC 两种模式
}
ServerConfig 服务器配置
type ServiceConfig ¶
type ServiceConfig struct {
Address string `yaml:"address" env:"RPC_ADDRESS" required:"true"`
}
ServiceConfig RPC 服务配置
type ServiceRegistration ¶
type ServiceRegistration struct {
// Name 服务名称
Name string
// GRPCRegister gRPC 服务注册函数
GRPCRegister GRPCServiceRegister
// GatewayRegister 网关服务注册函数(可选)
GatewayRegister GatewayServiceRegister
}
ServiceRegistration 服务注册信息
type ServiceRegistry ¶
type ServiceRegistry struct {
// contains filtered or unexported fields
}
ServiceRegistry 服务注册表
func (*ServiceRegistry) GetServices ¶
func (r *ServiceRegistry) GetServices() []ServiceRegistration
GetServices 获取所有注册的服务
func (*ServiceRegistry) Register ¶
func (r *ServiceRegistry) Register(reg ServiceRegistration)
Register 注册服务
func (*ServiceRegistry) RegisterAll ¶
func (r *ServiceRegistry) RegisterAll(regs ...ServiceRegistration)
RegisterAll 批量注册服务
func (*ServiceRegistry) RegisterToGRPCServer ¶
func (r *ServiceRegistry) RegisterToGRPCServer(server *grpc.Server)
RegisterToGRPCServer 将所有服务注册到 gRPC 服务器
func (*ServiceRegistry) RegisterToGateway ¶
func (r *ServiceRegistry) RegisterToGateway(ctx context.Context, gwHandler interface { RegisterService(ctx context.Context, grpcAddr string, registerFunc func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error, opts ...grpc.DialOption) error }, grpcAddr string, opts []grpc.DialOption) error
RegisterToGateway 将所有服务注册到 HTTP 网关 使用 gateway.GatewayHandler 的 RegisterService 方法