https://github.com/steinfletcher/conf
A library to parse configuration data using struct tags
https://github.com/steinfletcher/conf
Last synced: about 1 year ago
JSON representation
A library to parse configuration data using struct tags
- Host: GitHub
- URL: https://github.com/steinfletcher/conf
- Owner: steinfletcher
- Created: 2019-10-08T21:45:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-18T14:41:08.000Z (over 6 years ago)
- Last Synced: 2025-02-02T10:37:30.380Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/steinfletcher/conf)
# conf
Extends https://github.com/caarlos0/env to support arbitrary data providers. This means you can resolve data from anywhere, such as Vault, AWS Secrets manager, S3 or Google Sheets.
# Usage
Implement the config Provider interface
```go
type Provider interface {
Provide(field reflect.StructField) (string, error)
}
```
Create custom struct tags
```go
type Config struct {
// github.com/caarlos0/env properties
Home string `env:"HOME"`
Port int `env:"PORT" envDefault:"3000"`
IsProduction bool `env:"PRODUCTION"`
Hosts []string `env:"HOSTS" envSeparator:":"`
Duration time.Duration `env:"DURATION"`
TempFolder string `env:"TEMP_FOLDER" envDefault:"${HOME}/tmp" envExpand:"true"`
// custom properties
MySecret string `secret:"MY_SECRET,required"`
}
```
Pass config providers to `conf.Parse(...)` like so
```go
var cfg Config
err := env.Parse(&cfg, conf.EnvProvider, myCustomProvider)
```
where `conf.EnvProvider` is the environment variable parser from `caarlos0/env` and `myCustomProvider` is the custom provider.
# Providers
* [AWS Secrets Manager](https://github.com/steinfletcher/aws-secrets-manager-conf) for resolving secrets from AWS secrets manager.