Skip to content
forked from wgarunap/goconf

Load environmental variable values to go struct directly

License

Notifications You must be signed in to change notification settings

SourceParts/goconf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Config

Library to load env configuration

How to use it

package main
import (

"errors"
"github.com/caarlos0/env/v6"
"github.com/wgarunap/goconf"
"log"
)

type Conf struct {
	Name string `env:"MY_NAME"`
}

var Config Conf

func (Conf) Register()error {
	return env.Parse(&Config)
}

func (Conf) Validate() error{
	if Config.Name == "" {
		return errors.New(`MY_NAME environmental variable cannot be empty`)
	}
    return nil
}

func (Conf) Print() interface{} {
	return Config
}

func main() {
	err := goconf.Load(
		new(Conf),
	)
    if err != nil{
           log.Fatal(err)
    }
    log.Print(`configuration loaded, `,Config.Name)
}

About

Load environmental variable values to go struct directly

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%