Documentation
¶
Index ¶
- Constants
- func NewStorageProvider(cfg *config.ConfigManager) (storage.Provider, error)
- func OpenTelemetrySetup(serviceName string, options ...func(*TracerConfig)) (io.Closer, error)
- func Register(container *dig.Container) error
- func TypedProvider[T any](pm *ProviderManager, name string) (T, error)
- type CloudServiceProvider
- type ComponentHealth
- type ContainerAdapter
- func (ca *ContainerAdapter) GetCPULimit() float64
- func (ca *ContainerAdapter) GetConfig() ContainerConfig
- func (ca *ContainerAdapter) GetContainerID() string
- func (ca *ContainerAdapter) GetEnvironment() string
- func (ca *ContainerAdapter) GetMemoryLimit() int64
- func (ca *ContainerAdapter) GetShutdownTimeout() time.Duration
- func (ca *ContainerAdapter) GetWorkDir() string
- func (ca *ContainerAdapter) IsInContainer() bool
- type ContainerConfig
- type GracefulManager
- type GracefulServer
- type HealthCheck
- type HealthCheckConfig
- type HealthManager
- func (hm *HealthManager) GetAllHealth() map[string]*ComponentHealth
- func (hm *HealthManager) GetHealth(name string) *ComponentHealth
- func (hm *HealthManager) Handler() http.Handler
- func (hm *HealthManager) IsHealthy(name string) bool
- func (hm *HealthManager) IsSystemHealthy() bool
- func (hm *HealthManager) RegisterCheck(name string, check HealthCheck, config ...HealthCheckConfig)
- func (hm *HealthManager) RegisterHandlers(mux *http.ServeMux)
- func (hm *HealthManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (hm *HealthManager) Start()
- func (hm *HealthManager) Stop()
- func (hm *HealthManager) UnregisterCheck(name string)
- type HealthStatus
- type LifecycleManager
- func (lm *LifecycleManager) AddShutdownCallback(callback ShutdownCallback)
- func (lm *LifecycleManager) SetShutdownTimeout(timeout time.Duration)
- func (lm *LifecycleManager) Shutdown()
- func (lm *LifecycleManager) ShutdownContext() (context.Context, context.CancelFunc)
- func (lm *LifecycleManager) Start()
- func (lm *LifecycleManager) WaitForShutdown()
- type ProviderManager
- func (pm *ProviderManager) CheckHealthAll(ctx context.Context) map[string]error
- func (pm *ProviderManager) GetProvider(name string) (providers.Provider, error)
- func (pm *ProviderManager) GetProviderNames() []string
- func (pm *ProviderManager) HasProvider(name string) bool
- func (pm *ProviderManager) InitProviders(ctx context.Context) error
- func (pm *ProviderManager) RegisterProvider(provider providers.Provider) error
- type ShutdownCallback
- type Tracer
- type TracerConfig
- type TracerProvider
- type TracingManager
- func (tm *TracingManager) CreateTracer(name string) trace.Tracer
- func (tm *TracingManager) Init() error
- func (tm *TracingManager) Provider() trace.TracerProvider
- func (tm *TracingManager) Shutdown(ctx context.Context) error
- func (tm *TracingManager) TraceFunction(ctx context.Context, name string, fn func(context.Context) error) error
- func (tm *TracingManager) TraceHTTPMiddleware() interface{}
- func (tm *TracingManager) Tracer() trace.Tracer
Constants ¶
const ( ProviderAWS = "aws" ProviderAliyun = "aliyun" ProviderHuawei = "huawei" )
云服务提供商类型
Variables ¶
This section is empty.
Functions ¶
func NewStorageProvider ¶ added in v1.1.4
func NewStorageProvider(cfg *config.ConfigManager) (storage.Provider, error)
NewStorageProvider 创建存储提供商实例
func OpenTelemetrySetup ¶
func OpenTelemetrySetup(serviceName string, options ...func(*TracerConfig)) (io.Closer, error)
OpenTelemetrySetup 创建一个全局使用的便捷函数
func TypedProvider ¶
func TypedProvider[T any](pm *ProviderManager, name string) (T, error)
TypedProvider 泛型函数,获取特定类型的提供商
Types ¶
type CloudServiceProvider ¶ added in v1.1.4
type CloudServiceProvider struct {
*app.BaseProvider
}
CloudServiceProvider 云服务提供者
func NewCloudServiceProvider ¶ added in v1.1.4
func NewCloudServiceProvider() *CloudServiceProvider
NewCloudServiceProvider 创建云服务提供者
func (*CloudServiceProvider) Boot ¶ added in v1.1.4
func (p *CloudServiceProvider) Boot(app *app.Application) error
Boot 启动云服务
func (*CloudServiceProvider) Register ¶ added in v1.1.4
func (p *CloudServiceProvider) Register(app *app.Application) error
Register 注册云服务到DI容器
type ComponentHealth ¶
type ComponentHealth struct {
// 组件名称
Name string `json:"name"`
// 组件状态
Status HealthStatus `json:"status"`
// 上次检查时间
LastCheck time.Time `json:"last_check"`
// 错误信息(如果有)
Error string `json:"error,omitempty"`
// 连续失败次数
FailureCount int `json:"failure_count,omitempty"`
// 连续成功次数
SuccessCount int `json:"success_count,omitempty"`
// 额外信息
Details map[string]interface{} `json:"details,omitempty"`
}
ComponentHealth 组件健康状态
type ContainerAdapter ¶
type ContainerAdapter struct {
// contains filtered or unexported fields
}
ContainerAdapter 容器环境适配器
func NewContainerAdapter ¶
func NewContainerAdapter(config ContainerConfig) *ContainerAdapter
NewContainerAdapter 创建容器适配器
func (*ContainerAdapter) GetCPULimit ¶
func (ca *ContainerAdapter) GetCPULimit() float64
GetCPULimit 获取CPU限制
func (*ContainerAdapter) GetConfig ¶
func (ca *ContainerAdapter) GetConfig() ContainerConfig
GetConfig 获取容器配置
func (*ContainerAdapter) GetContainerID ¶
func (ca *ContainerAdapter) GetContainerID() string
GetContainerID 获取容器ID
func (*ContainerAdapter) GetEnvironment ¶
func (ca *ContainerAdapter) GetEnvironment() string
GetEnvironment 获取当前环境名称
func (*ContainerAdapter) GetMemoryLimit ¶
func (ca *ContainerAdapter) GetMemoryLimit() int64
GetMemoryLimit 获取内存限制
func (*ContainerAdapter) GetShutdownTimeout ¶
func (ca *ContainerAdapter) GetShutdownTimeout() time.Duration
GetShutdownTimeout 获取优雅关闭超时时间
func (*ContainerAdapter) GetWorkDir ¶
func (ca *ContainerAdapter) GetWorkDir() string
GetWorkDir 获取工作目录
func (*ContainerAdapter) IsInContainer ¶
func (ca *ContainerAdapter) IsInContainer() bool
IsInContainer 检查是否在容器环境中运行
type ContainerConfig ¶
type ContainerConfig struct {
// 是否在容器环境中运行
InContainer bool
// 容器ID,通常是Docker容器ID或K8s Pod名称
ContainerID string
// 工作目录
WorkDir string
// 容器平台(docker, k8s, ecs等)
Platform string
// 环境名称(dev, test, prod等)
Environment string
// 自动检测到的内存限制(字节)
MemoryLimit int64
// 自动检测到的CPU限制(核心数)
CPULimit float64
// 优雅关闭超时(秒)
ShutdownTimeout int
}
ContainerConfig 容器化环境配置
func DefaultContainerConfig ¶
func DefaultContainerConfig() ContainerConfig
DefaultContainerConfig 返回默认的容器配置
type GracefulManager ¶
type GracefulManager struct {
// contains filtered or unexported fields
}
GracefulManager 优雅启动和关闭管理器
func NewGracefulManager ¶
func NewGracefulManager(timeout time.Duration) *GracefulManager
NewGracefulManager 创建优雅启动和关闭管理器
func (*GracefulManager) AddServer ¶
func (gm *GracefulManager) AddServer(server GracefulServer)
AddServer 添加服务器
func (*GracefulManager) CustomShutdownHandler ¶
func (gm *GracefulManager) CustomShutdownHandler(handler ShutdownCallback)
CustomShutdownHandler 定义自定义关闭处理函数
func (*GracefulManager) SetShutdownTimeout ¶
func (gm *GracefulManager) SetShutdownTimeout(timeout time.Duration)
SetShutdownTimeout 设置关闭超时
type GracefulServer ¶
type GracefulServer interface {
// Start 启动服务器
Start() error
// Stop 停止服务器
Stop(ctx context.Context) error
}
GracefulServer 支持优雅启动和关闭的服务器接口
type HealthCheck ¶
type HealthCheck func(ctx context.Context) (HealthStatus, error)
HealthCheck 定义健康检查函数类型
type HealthCheckConfig ¶
type HealthCheckConfig struct {
// 检查间隔
Interval time.Duration
// 超时时间
Timeout time.Duration
// 初始延迟(应用启动后多久开始检查)
InitialDelay time.Duration
// 失败阈值(连续失败多少次认为组件不健康)
FailureThreshold int
// 成功阈值(连续成功多少次认为组件恢复健康)
SuccessThreshold int
}
HealthCheckConfig 健康检查配置
func DefaultHealthCheckConfig ¶
func DefaultHealthCheckConfig() HealthCheckConfig
DefaultHealthCheckConfig 返回默认健康检查配置
type HealthManager ¶
type HealthManager struct {
// contains filtered or unexported fields
}
HealthManager 健康检查管理器
func (*HealthManager) GetAllHealth ¶
func (hm *HealthManager) GetAllHealth() map[string]*ComponentHealth
GetAllHealth 获取所有组件健康状态
func (*HealthManager) GetHealth ¶
func (hm *HealthManager) GetHealth(name string) *ComponentHealth
GetHealth 获取特定组件健康状态
func (*HealthManager) IsHealthy ¶
func (hm *HealthManager) IsHealthy(name string) bool
IsHealthy 检查特定组件是否健康
func (*HealthManager) IsSystemHealthy ¶
func (hm *HealthManager) IsSystemHealthy() bool
IsSystemHealthy 检查整个系统是否健康
func (*HealthManager) RegisterCheck ¶
func (hm *HealthManager) RegisterCheck(name string, check HealthCheck, config ...HealthCheckConfig)
RegisterCheck 注册健康检查
func (*HealthManager) RegisterHandlers ¶
func (hm *HealthManager) RegisterHandlers(mux *http.ServeMux)
RegisterHandlers 将健康检查处理函数注册到HTTP服务器
func (*HealthManager) ServeHTTP ¶
func (hm *HealthManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP 实现HTTP处理函数
func (*HealthManager) UnregisterCheck ¶
func (hm *HealthManager) UnregisterCheck(name string)
UnregisterCheck 注销健康检查
type HealthStatus ¶
type HealthStatus string
HealthStatus 定义了健康状态类型
const ( // StatusHealthy 表示组件健康 StatusHealthy HealthStatus = "healthy" // StatusUnhealthy 表示组件不健康 StatusUnhealthy HealthStatus = "unhealthy" // StatusDegraded 表示组件性能下降但仍可工作 StatusDegraded HealthStatus = "degraded" // StatusStarting 表示组件正在启动 StatusStarting HealthStatus = "starting" // StatusStopping 表示组件正在停止 StatusStopping HealthStatus = "stopping" )
type LifecycleManager ¶
type LifecycleManager struct {
// contains filtered or unexported fields
}
LifecycleManager 生命周期管理器
func NewLifecycleManager ¶
func NewLifecycleManager(timeout time.Duration) *LifecycleManager
NewLifecycleManager 创建生命周期管理器
func (*LifecycleManager) AddShutdownCallback ¶
func (lm *LifecycleManager) AddShutdownCallback(callback ShutdownCallback)
AddShutdownCallback 添加关闭回调
func (*LifecycleManager) SetShutdownTimeout ¶
func (lm *LifecycleManager) SetShutdownTimeout(timeout time.Duration)
SetShutdownTimeout 设置关闭超时
func (*LifecycleManager) ShutdownContext ¶
func (lm *LifecycleManager) ShutdownContext() (context.Context, context.CancelFunc)
ShutdownContext 创建关闭上下文
func (*LifecycleManager) WaitForShutdown ¶
func (lm *LifecycleManager) WaitForShutdown()
WaitForShutdown 等待关闭信号
type ProviderManager ¶
type ProviderManager struct {
// contains filtered or unexported fields
}
ProviderManager 云服务提供商管理器
func (*ProviderManager) CheckHealthAll ¶
func (pm *ProviderManager) CheckHealthAll(ctx context.Context) map[string]error
CheckHealthAll 检查所有云服务提供商的健康状态
func (*ProviderManager) GetProvider ¶
func (pm *ProviderManager) GetProvider(name string) (providers.Provider, error)
GetProvider 获取云服务提供商
func (*ProviderManager) GetProviderNames ¶
func (pm *ProviderManager) GetProviderNames() []string
GetProviderNames 获取所有已注册的云服务提供商名称
func (*ProviderManager) HasProvider ¶
func (pm *ProviderManager) HasProvider(name string) bool
HasProvider 检查是否存在指定的云服务提供商
func (*ProviderManager) InitProviders ¶
func (pm *ProviderManager) InitProviders(ctx context.Context) error
InitProviders 初始化所有云服务提供商
func (*ProviderManager) RegisterProvider ¶
func (pm *ProviderManager) RegisterProvider(provider providers.Provider) error
RegisterProvider 注册云服务提供商
type ShutdownCallback ¶
ShutdownCallback 定义关闭回调函数类型
type TracerConfig ¶
type TracerConfig struct {
// 服务名称
ServiceName string
// 服务版本
ServiceVersion string
// 服务环境(如:production, staging, development)
Environment string
// 导出器类型:stdout, jaeger, otlp
ExporterType string
// 采样率 (0.0-1.0)
SamplingRate float64
// Jaeger端点 (如: http://jaeger:14268/api/traces)
JaegerEndpoint string
// OTLP端点 (如: localhost:4317)
OTLPEndpoint string
// 启用批处理
Batching bool
// 批处理最大导出数量
BatchMaxExportSize int
// 批处理延迟
BatchDelay time.Duration
// 启用传播器
EnablePropagation bool
// 启用调试信息
Debug bool
}
TracerConfig 追踪配置
type TracingManager ¶
type TracingManager struct {
// contains filtered or unexported fields
}
TracingManager 分布式追踪管理器
func NewTracingManager ¶
func NewTracingManager(config TracerConfig) *TracingManager
NewTracingManager 创建分布式追踪管理器
func (*TracingManager) CreateTracer ¶
func (tm *TracingManager) CreateTracer(name string) trace.Tracer
创建一个Tracer的便捷函数
func (*TracingManager) Provider ¶
func (tm *TracingManager) Provider() trace.TracerProvider
Provider 获取TracerProvider实例
func (*TracingManager) Shutdown ¶
func (tm *TracingManager) Shutdown(ctx context.Context) error
Shutdown 关闭追踪管理器
func (*TracingManager) TraceFunction ¶
func (tm *TracingManager) TraceFunction(ctx context.Context, name string, fn func(context.Context) error) error
TraceFunction 包装函数执行并添加追踪
func (*TracingManager) TraceHTTPMiddleware ¶
func (tm *TracingManager) TraceHTTPMiddleware() interface{}
TraceHTTPMiddleware 创建HTTP追踪中间件