An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

[![Build Status](https://travis-ci.org/steinfletcher/conf.svg?branch=master)](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.