config

package
v0.0.0-...-214c4de Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseConnection

func DatabaseConnection(dbConfig DatabaseConfig) (*adapters.Database, error)

DatabaseConnection establishes a connection to the MongoDB database.

func NewRateLimit

func NewRateLimit(rateConfig *RateLimiterConfig) *redis_rate.Limit

NewRateLimit creates a rate limiter configuration.

func QueueRedisConfig

func QueueRedisConfig(redisConfig RedisConfig) *asynq.RedisClientOpt

QueueRedisConfig returns Redis configuration for the task queue.

func RedisConnection

func RedisConnection(redisConfig RedisConfig) *adapters.Redis

RedisConnection establishes a connection to the Redis database.

func SetupLogger

func SetupLogger(env string)

SetupLogger configures the global logger based on the environment.

Types

type Config

type Config struct {
	Server      ServerConfig              `mapstructure:"server"`
	Database    DatabaseConfig            `mapstructure:"database"`
	JWT         services.JWTConfig        `mapstructure:"jwt"`
	Redis       RedisConfig               `mapstructure:"redis"`
	Env         string                    `mapstructure:"env"` // Current application environment (e.g., development, production).
	Scheduler   SchedulerConfig           `mapstructure:"scheduler"`
	QueueWorker QueueWorkerConfig         `mapstructure:"queue_worker"`
	Email       notifications.EmailConfig `mapstructure:"email"`

	RateLimiter struct {
		App RateLimiterConfig `mapstructure:"app"` // Application-level rate limiter settings.
	} `mapstructure:"rate_limiter"`
}

Config holds the complete application configuration.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads the application configuration from a YAML file or environment variables.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks for missing or invalid configuration fields.

type DatabaseConfig

type DatabaseConfig struct {
	URL  string `mapstructure:"url"`
	Name string `mapstructure:"name"`
}

DatabaseConfig holds the MongoDB connection details.

type QueueWorkerConfig

type QueueWorkerConfig struct {
	Concurrency   int      `mapstructure:"concurrency"`     // Number of concurrent workers.
	QueueName     string   `mapstructure:"queue_name"`      // Name of the queue to process.
	EnabledForEnv []string `mapstructure:"enabled_for_env"` // Environments where the worker is enabled.
}

QueueWorkerConfig holds the configuration for the queue worker.

type RateLimiterConfig

type RateLimiterConfig struct {
	Rate   int           `mapstructure:"rate"`   // Maximum requests per period.
	Burst  int           `mapstructure:"burst"`  // Maximum burst capacity.
	Period time.Duration `mapstructure:"period"` // Time period for rate limiting.
}

RateLimiterConfig defines the rate limiting settings.

type RedisConfig

type RedisConfig struct {
	URL      string `mapstructure:"url"`
	Password string `mapstructure:"password"`
	DB       int    `mapstructure:"db"`
}

RedisConfig holds the Redis connection details.

type SchedulerConfig

type SchedulerConfig struct {
	Interval      time.Duration `mapstructure:"interval"`        // Polling interval for reminders.
	ReminderDays  []int         `mapstructure:"reminder_days"`   // Days before renewal to send reminders.
	EnabledForEnv []string      `mapstructure:"enabled_for_env"` // Environments where the scheduler is enabled.
}

SchedulerConfig holds the configuration for the subscription scheduler.

type ServerConfig

type ServerConfig struct {
	Port int `mapstructure:"port"`
	TLS  struct {
		Enabled  bool   `mapstructure:"enabled"`
		CertPath string `mapstructure:"cert_path"`
		KeyPath  string `mapstructure:"key_path"`
	} `mapstructure:"tls"`
}

ServerConfig holds the server configuration, including TLS settings.

Jump to

Keyboard shortcuts

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