go get -u github.com/tinh-tinh/config/v2The Config module for the Tinh Tinh framework provides flexible configuration management for Go applications. It supports loading environment variables from .env files and struct-based configs from YAML, with first-class integration for dependency injection and modular apps.
- Load configuration from
.env,.yaml, or.ymlfiles - Strongly-typed config structs with tags for mapping, default values, and validation
- Namespace-based config injection for multiple configs (e.g., database, cache)
- Conditional module registration based on environment or custom logic
- Supports default values and validation via struct tags
- Seamless integration with Tinh Tinh modules and controllers
import "github.com/tinh-tinh/config/v2"
type Config struct {
NodeEnv string `env:"NODE_ENV"`
Port int `env:"PORT"`
ExpiresIn time.Duration `env:"EXPIRES_IN"`
Log bool `env:"LOG"`
Secret string `env:"SECRET"`
}
cfg, err := config.NewEnv[Config](".env")
if err != nil {
panic(err)
}
fmt.Println(cfg.Port)type YamlConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
}
cfg, err := config.NewYaml[YamlConfig]("config.yaml")
if err != nil {
panic(err)
}
fmt.Println(cfg.Host)import "github.com/tinh-tinh/tinhtinh/v2/core"
appModule := core.NewModule(core.NewModuleOptions{
Imports: []core.Modules{
config.ForRoot[AppConfig](".env"),
},
})cfg := config.Inject[AppConfig](module)
fmt.Println(cfg.Port)We welcome contributions! Please feel free to submit a Pull Request.
If you encounter any issues or need help, you can:
- Open an issue in the GitHub repository
- Check our documentation
- Join our community discussions