A minimalistic approach to spf13/viper.
- Read
ENV
variables into astruct
- Read a
.env
file into astruct
< 100
source lines of code- No dependencies
Only string fields are supported.
type Config struct {
UserConfig struct {
Email string `env:"MY_APP_EMAIL"`
Password string `env:"MY_APP_PASSWORD"`
someOtherProperty string
}
Endpoint string `env:"MY_APP_ENDPOINT"`
}
func main() {
//cfg, err := NewEnvConfig[Config]() //Read from env
cfg, err := NewEnvFileConfig[Config](".env.sample") //Read from .env file
if err != nil {
panic(err)
}
fmt.Println("%+v", cfg)
}