Documentation
¶
Overview ¶
Package component provides interface definitions for components This is the lowest level package, which does not depend on any business packages to avoid circular dependencies.
Package component provides component interface definitions
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigLoader ¶
type ConfigLoader interface {
// Get configuration item
//
// Parameters:
// key: configuration key (e.g., "redis.main.host")
//
// Return:
// interface{}: configuration value
Get(key string) interface{}
// Unmarshal deserializes the configuration into a struct
//
// Parameters:
// key: Configuration key (e.g., "redis" reads the entire redis configuration section)
// v: pointer to the target struct
//
// Return:
// error: return error on deserialization failure
//
// Example:
// var redisConfigs map[string]redis.Config
// if err := loader.Unmarshal("redis", &redisConfigs); err != nil {
// return err
// }
Unmarshal(key string, v interface{}) error
// GetString Get string configuration
GetString(key string) string
// Get integer configuration
GetInt(key string) int
// GetBool Get boolean configuration
GetBool(key string) bool
// Check if the configuration item exists
IsSet(key string) bool
}
ConfigLoader configuration loader interface
Provides unified configuration reading capability, components read their own configurations through this interface Avoid component dependencies on specific configuration structures (such as AppConfig)
type HealthCheckProvider ¶
type HealthCheckProvider interface {
GetHealthChecker() HealthChecker
}
HealthCheckProvider health check provider interface Components optionally implement this interface to provide health checkers
type HealthChecker ¶
type HealthChecker interface {
// Check execution health status
// Return nil indicates healthy, return error indicates unhealthy
Check(ctx context.Context) error
// Name returns the check item name (e.g., "database", "redis")
Name() string
}
HealthChecker health check interface Components optionally implement this interface to provide health check capabilities
type MetricsCollector ¶
type MetricsCollector interface {
// Register registers a MetricsProvider with the registry.
// The provider's RegisterMetrics will be called with a pre-configured Meter.
Register(provider MetricsProvider) error
// GetMeter returns a Meter for the given component name.
// The meter is pre-configured with base labels.
GetMeter(name string) metric.Meter
// GetBaseLabels returns the global base labels (service_name, env, etc.).
GetBaseLabels() []attribute.KeyValue
// IsEnabled returns whether metrics collection is globally enabled.
IsEnabled() bool
}
MetricsCollector defines the interface for the centralized metrics registry. This interface is implemented by telemetry.MetricsRegistry.
type MetricsProvider ¶
type MetricsProvider interface {
// MetricsName returns the metrics group name (used for Meter naming).
// Should be a short, lowercase identifier like "redis", "kafka", "jwt".
MetricsName() string
// RegisterMetrics registers all metrics for this component.
// Called by MetricsRegistry after component Init.
// The meter is pre-configured with the component's namespace.
RegisterMetrics(meter metric.Meter) error
// IsMetricsEnabled returns whether metrics collection is enabled for this component.
IsMetricsEnabled() bool
}
MetricsProvider defines the interface for components that provide metrics. Components can optionally implement this interface to register their metrics with the centralized MetricsRegistry.
Example implementation:
func (c *Component) MetricsName() string {
return "redis"
}
func (c *Component) RegisterMetrics(meter metric.Meter) error {
counter, err := meter.Int64Counter("redis_commands_total")
if err != nil {
return err
}
c.commandsCounter = counter
return nil
}
func (c *Component) IsMetricsEnabled() bool {
return c.config.Metrics.Enabled
}