Something went wrong. Try again.
A minimalistic version of spf13/viper.
Something went wrong. Try again.
Files
Verified signature Signed by thegabriel.eu SHA256:4Bjd9DerB5SI+pUzr/KEF7me15ZMiE6kvMiikGqIi/Y Click to copy SHA
Verified signature Signed by thegabriel.eu SHA256:4Bjd9DerB5SI+pUzr/KEF7me15ZMiE6kvMiikGqIi/Y Click to copy SHA
v1.0.0 Latest
- Go 100%
README.md
tinyviper #
A minimalistic version of spf13/viper.
This is a copy from the amazing tiny-viper project.
The module here differs only in that it has a non-github module path, since I want to contribute to unlinking from bigtech.
Installation #
go get thegabriel.eu/tinyviper@latest
Features #
- Read
ENVvariables into astruct - Read a
.envfile into astruct < 110source lines of code- No dependencies
Only string fields are supported. Allows missing env variables when marked with "omitempty"
Usage #
package main
import (
"thegabriel.eu/tinyviper"
"fmt"
)
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"`
AppUrl string `env:MY_APP_URL,omitempty`
}
func main() {
cfg := Config{Endpoint: "some default endpoint"}
err := tinyviper.LoadFromResolver(&cfg, tinyviper.NewEnvResolver(), tinyviper.NewEnvFileResolver(".env.sample"))
if err != nil {
panic(err)
}
fmt.Println("%+v", cfg)
}