https://github.com/tinh-tinh/config
⚙️ Config Module for Tinh Tinh framwork
https://github.com/tinh-tinh/config
configuration framework
Last synced: 2 months ago
JSON representation
⚙️ Config Module for Tinh Tinh framwork
- Host: GitHub
- URL: https://github.com/tinh-tinh/config
- Owner: tinh-tinh
- License: mit
- Created: 2024-10-23T13:43:20.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-20T04:05:43.000Z (9 months ago)
- Last Synced: 2025-07-20T05:46:59.605Z (9 months ago)
- Topics: configuration, framework
- Language: Go
- Homepage: https://tinh-tinh.github.io/docs/docs/intergrations/config
- Size: 52.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Config Module for Tinh Tinh
## Install
```bash
go get -u github.com/tinh-tinh/config/v2
```
## Overview
The 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.
## Features
- Load configuration from `.env`, `.yaml`, or `.yml` files
- 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
## Quick Start
### 1. Basic Usage with `.env`
```go
import "github.com/tinh-tinh/config/v2"
type AppConfig struct {
NodeEnv string `mapstructure:"NODE_ENV"`
Port int `mapstructure:"PORT"`
ExpiresIn time.Duration `mapstructure:"EXPIRES_IN"`
Log bool `mapstructure:"LOG"`
Secret string `mapstructure:"SECRET"`
}
cfg, err := config.NewEnv[AppConfig](".env")
if err != nil {
panic(err)
}
fmt.Println(cfg.Port)
```
### 2. Using with YAML
```go
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)
```
---
## Tinh Tinh Module Integration
### Register as a Global Config
```go
import "github.com/tinh-tinh/tinhtinh/v2/core"
appModule := core.NewModule(core.NewModuleOptions{
Imports: []core.Modules{
config.ForRoot[AppConfig](".env"),
},
})
```
### Inject Config Anywhere
```go
cfg := config.Inject[AppConfig](module)
fmt.Println(cfg.Port)
```
## Contributing
We welcome contributions! Please feel free to submit a Pull Request.
## Support
If you encounter any issues or need help, you can:
- Open an issue in the GitHub repository
- Check our documentation
- Join our community discussions