Skip to content

Configuration

type Config struct {
Port int `env:"PORT" default:"9900"`
DBURL string `env:"DB_URL" required:"true"`
Timeout time.Duration `env:"TIMEOUT" default:"5s"`
Origins []string `env:"CORS_ORIGINS"` // comma separated
Redis RedisConfig `envPrefix:"REDIS_"` // REDIS_ADDR, REDIS_DB, ...
}
// Global module: every provider can take *Config.
Imports: []*dygo.Module{config.ForRoot[Config](config.Files(".env.local", ".env"))}
// Or load it yourself before Create (for the listen address, middleware options):
cfg, err := config.Load[Config](config.Files(".env"))

Real environment variables win over .env files. Every missing or bad value is reported together and stops the boot. config.ForFeature[T](config.Prefix("USERS_")) is a non-global module for one feature’s settings; config.Env(map) replaces the environment in tests; config.Validate(schema) runs a validation schema after loading.