Skip to content

nobloat/tinyviper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiny-viper WIP

ci workflow

A minimalistic approach to spf13/viper.

Features

  • Read ENV variables into a struct
  • Read a .env file into a struct
  • < 100 source lines of code
  • No dependencies

Only string fields are supported.

Usage

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)
}

About

A minimalistic approach to spf13/viper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages