Skip to content

nobloat/tinyviper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiny-viper

ci workflow

A minimalistic approach to spf13/viper.

Features

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

Only string fields are supported.

Usage

package main

import (
	"github.com/nobloat/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"`
}

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

About

A minimalistic approach to spf13/viper

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages