Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/core-go/config
https://github.com/core-go/config
conf config configuration
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/core-go/config
- Owner: core-go
- Created: 2019-11-14T02:52:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-22T00:25:42.000Z (6 months ago)
- Last Synced: 2024-08-22T01:48:53.949Z (6 months ago)
- Topics: conf, config, configuration
- Language: Go
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# config
- Support to load the configurations
- Support to merge the environment variables to the configurations
- Support to override the configurations based on the environment (For example: SIT environment, UAT environment)## Installation
Please make sure to initialize a Go module before installing core-go/config:```shell
go get -u github.com/core-go/config
```Import:
```go
import "github.com/core-go/config"
```## Example
We have 2 config files, which are put into "configs" directory
- the default config file: config.yaml
- for SIT environment: config-sit.yaml#### config.yaml
```yaml
ldap:
server: localhost:389
binding_format: uid=%s,ou=users,dc=sample,dc=com,dc=vnredis_url: redis://localhost:6379
```In the SIT environment, we just override the configuration of ldap server and redis server:
#### config-sit.yaml
```yaml
ldap:
server: sit-server:389redis_url: redis://redis-sit:6379
``````go
type LDAPConfig struct {
Server string `mapstructure:"server"`
BindingFormat string `mapstructure:"binding_format"`
}type RootConfig struct {
Server app.ServerConfig `mapstructure:"server"`
Ldap LDAPConfig `mapstructure:"ldap"`
RedisClient string `mapstructure:"redis_client"`
}func main() {
env := os.Getenv("ENV")
var cfg RootConfig
// "authentication" is the directory, which contains source code
// "configs" is the directory, which contains config.yaml and config-sit.yaml
config.LoadConfigWithEnv("authentication", "configs", env, &cfg, "config")
log.Println("config ", cfg)var conf2 RootConfig
config.Load(&conf2, "configs/config")
log.Println("config2 ", conf2)
}
```