config

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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 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 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 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 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 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 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL