Filler
is a golang package pretty power you, when you want populate a structure with dynamic tags and implementation (we call these providers)
You will need the following things properly installed on your computer:
Filler is a library that you can to use for populate your structure from different data source, we have two implementation right now, but you can develop more
- The first one
envconfig
it has the power to get values from environment variables e.g :
provider.NewEnvProvider()
- The second one
ssm
it has the power to get values from aws parameter store
ssmProvider, err := provider.NewSsmProvider()
Now we need associated a provider to a tag, we can use suture config.ProviderByTag
e.g :
config.ProviderByTag{
Provider: provider.NewEnvProvider(),
Tag: "envconfig",
}
By read config and populate a struts just it`s necessary the next step,
- Create struts with tags
type (
DB struct {
URL string `ssm:"/base-path/second-path/value"`
Username string `envconfig:"DB_USER,optional" ssm:"/base-path/second-path/valueTwo"`
Password string `yml:"password" envconfig:"DB_PASS,optional"`
}
Server struct {
Port string `envconfig:"SERVER_PORT,optional"`
}
AppConfig struct {
DB
Server
IsDebug bool `envconfig:"DEBUG,optional"`
Environment string `envconfig:"ENVIRONMENT,optional"`
}
)
- Initialization config
appConfig := new(AppConfig)
err = config.Marshall(appConfig)
You can add a custom provider just need create a structured that implement an interface
type Provider interface {
Execute(*Context) (string, error)
}