 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package config - Hot Reload Configuration System Migrado de ClubPulse a gopherkit con mejoras significativas
Index ¶
- func ValidateConfig(config *BaseConfig) error
- type BaseConfig
- type CORSConfig
- type CacheConfig
- type CacheConfigDynamic
- type CircuitBreakerConfig
- type DatabaseConfig
- type DefaultLogger
- type DynamicConfig
- type ExternalConfig
- type FallbackConfigDynamic
- type HotReloadMetrics
- type HotReloader
- func (hr *HotReloader) GetConfig() *DynamicConfig
- func (hr *HotReloader) GetLastReloadTime() time.Time
- func (hr *HotReloader) GetMetrics() *HotReloadMetrics
- func (hr *HotReloader) GetWatchedFiles() []string
- func (hr *HotReloader) IsFeatureEnabled(featureName string) bool
- func (hr *HotReloader) IsRunning() bool
- func (hr *HotReloader) RegisterCallback(name string, callback ReloadCallback)
- func (hr *HotReloader) SaveConfig() error
- func (hr *HotReloader) Start() error
- func (hr *HotReloader) Stop() error
- func (hr *HotReloader) UpdateConfig(updates map[string]interface{}) error
 
- type JWTConfig
- type Logger
- type MonitoringConfigDynamic
- type ObservabilityConfig
- type RateLimitConfig
- type ReloadCallback
- type ReloadEvent
- type SecurityConfig
- type SecurityConfigDynamic
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateConfig ¶
func ValidateConfig(config *BaseConfig) error
ValidateConfig validates the configuration using struct tags
Types ¶
type BaseConfig ¶
type BaseConfig struct {
	Server        ServerConfig        `json:"server" validate:"required"`
	Database      DatabaseConfig      `json:"database" validate:"required"`
	Observability ObservabilityConfig `json:"observability"`
	Security      SecurityConfig      `json:"security"`
	Cache         CacheConfig         `json:"cache"`
	External      ExternalConfig      `json:"external"`
}
    BaseConfig holds common configuration for all services
func LoadBaseConfig ¶
func LoadBaseConfig(serviceName string) (*BaseConfig, error)
LoadBaseConfig loads base configuration from environment variables
func (*BaseConfig) IsDevelopment ¶
func (c *BaseConfig) IsDevelopment() bool
IsDevelopment returns true if the environment is development
func (*BaseConfig) IsProduction ¶
func (c *BaseConfig) IsProduction() bool
IsProduction returns true if the environment is production
func (*BaseConfig) IsStaging ¶
func (c *BaseConfig) IsStaging() bool
IsStaging returns true if the environment is staging
type CORSConfig ¶
type CORSConfig struct {
	AllowedOrigins   []string `json:"allowed_origins"`
	AllowedMethods   []string `json:"allowed_methods"`
	AllowedHeaders   []string `json:"allowed_headers"`
	ExposedHeaders   []string `json:"exposed_headers"`
	AllowCredentials bool     `json:"allow_credentials"`
	MaxAge           int      `json:"max_age"`
}
    CORSConfig holds CORS configuration
type CacheConfig ¶
type CacheConfig struct {
	Enabled  bool          `json:"enabled"`
	Host     string        `json:"host"`
	Port     string        `json:"port"`
	Password string        `json:"password"`
	DB       int           `json:"db"`
	Prefix   string        `json:"prefix"`
	TTL      time.Duration `json:"ttl"`
}
    CacheConfig holds cache-related configuration
type CacheConfigDynamic ¶ added in v1.0.2
type CacheConfigDynamic struct {
	Enabled            bool          `json:"enabled"`
	TTL                time.Duration `json:"ttl"`
	Namespace          string        `json:"namespace"`
	MaxSize            int64         `json:"max_size"`
	EvictionPolicy     string        `json:"eviction_policy"`
	CompressionEnabled bool          `json:"compression_enabled"`
	PrefetchEnabled    bool          `json:"prefetch_enabled"`
	CacheWarmupEnabled bool          `json:"cache_warmup_enabled"`
}
    CacheConfigDynamic configuración de cache que puede cambiar dinámicamente
type CircuitBreakerConfig ¶
type CircuitBreakerConfig struct {
	Enabled             bool          `json:"enabled"`
	MaxRequests         uint32        `json:"max_requests"`
	Interval            time.Duration `json:"interval"`
	Timeout             time.Duration `json:"timeout"`
	ReadyToTripRequests uint32        `json:"ready_to_trip_requests"`
	ReadyToTripRatio    float64       `json:"ready_to_trip_ratio"`
}
    CircuitBreakerConfig holds circuit breaker configuration
type DatabaseConfig ¶
type DatabaseConfig struct {
	URL             string        `json:"url"`
	Host            string        `json:"host"`
	Port            string        `json:"port"`
	Database        string        `json:"database"`
	User            string        `json:"user"`
	Password        string        `json:"password"`
	SSLMode         string        `json:"ssl_mode"`
	MaxOpenConns    int           `json:"max_open_conns"`
	MaxIdleConns    int           `json:"max_idle_conns"`
	ConnMaxLifetime time.Duration `json:"conn_max_lifetime"`
	ConnMaxIdleTime time.Duration `json:"conn_max_idle_time"`
}
    DatabaseConfig holds database-related configuration
func (*DatabaseConfig) GetDSN ¶
func (c *DatabaseConfig) GetDSN() string
GetDSN returns the database connection string
type DefaultLogger ¶ added in v1.0.2
type DefaultLogger struct{}
    DefaultLogger implementación simple de logger
func (*DefaultLogger) Debugf ¶ added in v1.0.2
func (dl *DefaultLogger) Debugf(format string, args ...interface{})
func (*DefaultLogger) Error ¶ added in v1.0.2
func (dl *DefaultLogger) Error(msg string)
func (*DefaultLogger) Info ¶ added in v1.0.2
func (dl *DefaultLogger) Info(msg string)
func (*DefaultLogger) Warn ¶ added in v1.0.2
func (dl *DefaultLogger) Warn(msg string)
func (*DefaultLogger) WithField ¶ added in v1.0.2
func (dl *DefaultLogger) WithField(key string, value interface{}) Logger
type DynamicConfig ¶ added in v1.0.2
type DynamicConfig struct {
	// Configuración de base de datos
	DatabaseMode   string `json:"database_mode"`
	DatabaseURL    string `json:"database_url"`
	DatabaseSchema string `json:"database_schema"`
	// Configuraciones específicas
	CacheConfig      CacheConfigDynamic      `json:"cache"`
	FallbackConfig   FallbackConfigDynamic   `json:"fallback"`
	SecurityConfig   SecurityConfigDynamic   `json:"security"`
	MonitoringConfig MonitoringConfigDynamic `json:"monitoring"`
	// Configuraciones adicionales
	FeatureFlags   map[string]bool   `json:"feature_flags"`
	CustomSettings map[string]string `json:"custom_settings"`
	// Metadatos
	LastUpdated time.Time `json:"last_updated"`
	Version     int       `json:"version"`
	LoadedFrom  string    `json:"loaded_from"`
	Environment string    `json:"environment"`
}
    DynamicConfig configuración que puede recargarse en caliente mejorada
type ExternalConfig ¶
type ExternalConfig struct {
	AuthAPIURL         string        `json:"auth_api_url"`
	UserAPIURL         string        `json:"user_api_url"`
	NotificationURL    string        `json:"notification_url"`
	CalendarAPIURL     string        `json:"calendar_api_url"`
	ChampionshipAPIURL string        `json:"championship_api_url"`
	Timeout            time.Duration `json:"timeout"`
	RetryAttempts      int           `json:"retry_attempts"`
	RetryDelay         time.Duration `json:"retry_delay"`
}
    ExternalConfig holds external service configuration
type FallbackConfigDynamic ¶ added in v1.0.2
type FallbackConfigDynamic struct {
	Enabled               bool          `json:"enabled"`
	HealthCheckInterval   time.Duration `json:"health_check_interval"`
	FailureThreshold      int           `json:"failure_threshold"`
	RecoveryCheckInterval time.Duration `json:"recovery_check_interval"`
	AlertWebhookURL       string        `json:"alert_webhook_url"`
	MaxRetryAttempts      int           `json:"max_retry_attempts"`
	AutoRecoveryEnabled   bool          `json:"auto_recovery_enabled"`
	NotificationsEnabled  bool          `json:"notifications_enabled"`
}
    FallbackConfigDynamic configuración de fallback que puede cambiar dinámicamente
type HotReloadMetrics ¶ added in v1.0.2
type HotReloadMetrics struct {
	TotalReloads       int64            `json:"total_reloads"`
	SuccessfulReloads  int64            `json:"successful_reloads"`
	FailedReloads      int64            `json:"failed_reloads"`
	CallbackExecutions int64            `json:"callback_executions"`
	WatchedFilesCount  int              `json:"watched_files_count"`
	AverageReloadTime  time.Duration    `json:"average_reload_time"`
	LastReloadTime     time.Time        `json:"last_reload_time"`
	ReloadHistory      []ReloadEvent    `json:"reload_history"`
	FileChangeEvents   map[string]int64 `json:"file_change_events"`
	CallbackErrors     map[string]int64 `json:"callback_errors"`
	// contains filtered or unexported fields
}
    HotReloadMetrics métricas del sistema de hot reload
type HotReloader ¶ added in v1.0.2
type HotReloader struct {
	// contains filtered or unexported fields
}
    HotReloader gestiona la recarga en caliente de configuraciones mejorado
func NewHotReloader ¶ added in v1.0.2
func NewHotReloader(configFile string, baseConfig *BaseConfig, logger Logger) (*HotReloader, error)
NewHotReloader crea un nuevo sistema de hot-reload mejorado
func (*HotReloader) GetConfig ¶ added in v1.0.2
func (hr *HotReloader) GetConfig() *DynamicConfig
GetConfig obtiene la configuración actual de forma thread-safe
func (*HotReloader) GetLastReloadTime ¶ added in v1.0.2
func (hr *HotReloader) GetLastReloadTime() time.Time
GetLastReloadTime obtiene el tiempo de la última recarga
func (*HotReloader) GetMetrics ¶ added in v1.0.2
func (hr *HotReloader) GetMetrics() *HotReloadMetrics
GetMetrics retorna las métricas del hot reloader
func (*HotReloader) GetWatchedFiles ¶ added in v1.0.2
func (hr *HotReloader) GetWatchedFiles() []string
GetWatchedFiles obtiene la lista de archivos observados
func (*HotReloader) IsFeatureEnabled ¶ added in v1.0.2
func (hr *HotReloader) IsFeatureEnabled(featureName string) bool
IsFeatureEnabled verifica si una feature flag está habilitada
func (*HotReloader) IsRunning ¶ added in v1.0.2
func (hr *HotReloader) IsRunning() bool
IsRunning verifica si el sistema está corriendo
func (*HotReloader) RegisterCallback ¶ added in v1.0.2
func (hr *HotReloader) RegisterCallback(name string, callback ReloadCallback)
RegisterCallback registra un callback para cambios de configuración
func (*HotReloader) SaveConfig ¶ added in v1.0.2
func (hr *HotReloader) SaveConfig() error
SaveConfig guarda la configuración actual al archivo
func (*HotReloader) Start ¶ added in v1.0.2
func (hr *HotReloader) Start() error
Start inicia el sistema de hot-reload mejorado
func (*HotReloader) Stop ¶ added in v1.0.2
func (hr *HotReloader) Stop() error
Stop detiene el sistema de hot-reload con limpieza mejorada
func (*HotReloader) UpdateConfig ¶ added in v1.0.2
func (hr *HotReloader) UpdateConfig(updates map[string]interface{}) error
UpdateConfig actualiza la configuración programáticamente mejorado
type JWTConfig ¶
type JWTConfig struct {
	Secret          string        `json:"secret" validate:"required,min=32"`
	RefreshSecret   string        `json:"refresh_secret"`
	AccessDuration  time.Duration `json:"access_duration"`
	RefreshDuration time.Duration `json:"refresh_duration"`
	Issuer          string        `json:"issuer"`
}
    JWTConfig holds JWT-related configuration
type Logger ¶ added in v1.0.2
type Logger interface {
	Info(msg string)
	Warn(msg string)
	Error(msg string)
	Debugf(format string, args ...interface{})
	WithField(key string, value interface{}) Logger
}
    Logger interface para logging
type MonitoringConfigDynamic ¶ added in v1.0.2
type MonitoringConfigDynamic struct {
	Enabled          bool    `json:"enabled"`
	MetricsEnabled   bool    `json:"metrics_enabled"`
	MetricsPort      int     `json:"metrics_port"`
	HealthCheckPort  int     `json:"health_check_port"`
	LogLevel         string  `json:"log_level"`
	SamplingRate     float64 `json:"sampling_rate"`
	AlertsEnabled    bool    `json:"alerts_enabled"`
	DashboardEnabled bool    `json:"dashboard_enabled"`
	TracingEnabled   bool    `json:"tracing_enabled"`
	ProfilerEnabled  bool    `json:"profiler_enabled"`
}
    MonitoringConfigDynamic configuración de monitoreo que puede cambiar dinámicamente
type ObservabilityConfig ¶
type ObservabilityConfig struct {
	TracingEnabled bool   `json:"tracing_enabled"`
	MetricsEnabled bool   `json:"metrics_enabled"`
	LogLevel       string `json:"log_level" validate:"oneof=debug info warn error"`
	ServiceName    string `json:"service_name" validate:"required"`
	ServiceVersion string `json:"service_version"`
	JaegerEndpoint string `json:"jaeger_endpoint"`
	OTLPEndpoint   string `json:"otlp_endpoint"`
}
    ObservabilityConfig holds observability-related configuration
type RateLimitConfig ¶
type RateLimitConfig struct {
	Enabled           bool          `json:"enabled"`
	RequestsPerMinute int           `json:"requests_per_minute"`
	BurstSize         int           `json:"burst_size"`
	WindowSize        time.Duration `json:"window_size"`
	RedisEnabled      bool          `json:"redis_enabled"`
}
    RateLimitConfig holds rate limiting configuration
type ReloadCallback ¶ added in v1.0.2
type ReloadCallback func(oldConfig, newConfig *DynamicConfig) error
ReloadCallback función que se ejecuta cuando cambia la configuración
type ReloadEvent ¶ added in v1.0.2
type ReloadEvent struct {
	File        string        `json:"file"`
	Type        string        `json:"type"`
	Timestamp   time.Time     `json:"timestamp"`
	Success     bool          `json:"success"`
	Error       string        `json:"error,omitempty"`
	Duration    time.Duration `json:"duration"`
	OldVersion  int           `json:"old_version"`
	NewVersion  int           `json:"new_version"`
	ChangedKeys []string      `json:"changed_keys,omitempty"`
}
    ReloadEvent evento de recarga mejorado
type SecurityConfig ¶
type SecurityConfig struct {
	RateLimit      RateLimitConfig      `json:"rate_limit"`
	CircuitBreaker CircuitBreakerConfig `json:"circuit_breaker"`
	CORS           CORSConfig           `json:"cors"`
	JWT            JWTConfig            `json:"jwt"`
}
    SecurityConfig holds security-related configuration
type SecurityConfigDynamic ¶ added in v1.0.2
type SecurityConfigDynamic struct {
	RLSEnabled        bool          `json:"rls_enabled"`
	JWTSecret         string        `json:"jwt_secret"`
	TokenTTL          time.Duration `json:"token_ttl"`
	RateLimitEnabled  bool          `json:"rate_limit_enabled"`
	RateLimitRPS      int           `json:"rate_limit_rps"`
	CORSOrigins       []string      `json:"cors_origins"`
	SecurityHeaders   bool          `json:"security_headers"`
	EncryptionEnabled bool          `json:"encryption_enabled"`
	AuditLogEnabled   bool          `json:"audit_log_enabled"`
}
    SecurityConfigDynamic configuración de seguridad que puede cambiar dinámicamente
type ServerConfig ¶
type ServerConfig struct {
	Port            string        `json:"port" validate:"required,min=4,max=5"`
	Environment     string        `json:"environment" validate:"required,oneof=development staging production"`
	MetricsPort     string        `json:"metrics_port" validate:"required,min=4,max=5"`
	ReadTimeout     time.Duration `json:"read_timeout"`
	WriteTimeout    time.Duration `json:"write_timeout"`
	IdleTimeout     time.Duration `json:"idle_timeout"`
	ShutdownTimeout time.Duration `json:"shutdown_timeout"`
	MaxRequestSize  int64         `json:"max_request_size"`
}
    ServerConfig holds server-related configuration