Documentation
¶
Overview ¶
Package infra contains the lowest-level resources needed by the microservice: configuration, the IoC container, lifecycle management, and logging setup.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitForShutdown ¶
WaitForShutdown blocks until an OS interrupt/term signal is received or the given context is cancelled. The caller is responsible for any cleanup after this function returns.
Types ¶
type Config ¶
type Config struct {
// HTTP server
ServerPort int `env:"SERVER_PORT" envDefault:"8080"`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
LogFormat string `env:"LOG_FORMAT" envDefault:"json"`
ReadTimeout time.Duration `env:"HTTP_READ_TIMEOUT" envDefault:"15s"`
WriteTimeout time.Duration `env:"HTTP_WRITE_TIMEOUT" envDefault:"15s"`
IdleTimeout time.Duration `env:"HTTP_IDLE_TIMEOUT" envDefault:"60s"`
// Database connection
DatabaseURL string `env:"DATABASE_URL" hush:"mask"`
// pgx connection pool tuning - all optional with production-ready defaults.
DBMaxConns int `env:"DB_MAX_CONNS" envDefault:"25"`
DBMinConns int `env:"DB_MIN_CONNS" envDefault:"2"`
DBMaxConnLifetime time.Duration `env:"DB_MAX_CONN_LIFETIME" envDefault:"30m"`
DBMaxConnIdleTime time.Duration `env:"DB_MAX_CONN_IDLE_TIME" envDefault:"5m"`
DBHealthCheckPeriod time.Duration `env:"DB_HEALTH_CHECK_PERIOD" envDefault:"1m"`
// Cleanup worker - all optional; zero values disable the feature.
CleanupInterval time.Duration `env:"CLEANUP_INTERVAL" envDefault:"1h"`
CleanupMaxAge time.Duration `env:"CLEANUP_MAX_AGE" envDefault:"0"`
CleanupKeepPerImage int `env:"CLEANUP_KEEP_PER_IMAGE" envDefault:"0"`
}
Config holds all runtime configuration loaded from environment variables.
Struct tags:
- env : environment variable name
- envDefault : fallback value when the variable is absent
- hush : "mask" or "hide" controls the printed config table
func Load ¶
Load reads all settings from environment variables via goconf and returns a validated *Config. On success goconf also prints a masked config table to stdout.
func (*Config) Print ¶
func (c *Config) Print() interface{}
Print implements goconf.Printer — returns the struct for the config table display.
func (*Config) Register ¶
Register implements goconf.Configer — parses environment variables into Config.
func (*Config) ServerAddress ¶
ServerAddress returns the formatted ":port" string for the HTTP server.
type Container ¶
type Container struct {
Config *Config
Logger zerolog.Logger
ScanRepo *postgres.ScanRepository
ScanUseCases *usecases.ScanUseCases
CleanupWorker *usecases.Cleaner
// contains filtered or unexported fields
}
Container is a simple implementation of a dependency inversion container.
Dependencies are resolved manually — there is no fancy DI framework. This makes startup explicit, testable, and easy to trace.
func NewResolvedContainer ¶
NewResolvedContainer builds and wires all dependencies, returning a ready-to-use Container. Call Destroy() when shutting down to release resources.