Skip to content
/ goconfig Public

Providing a simple method of constructing a struct using struct tags and mapping them to runtime environmental variables

License

Notifications You must be signed in to change notification settings

n-ask/goconfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goconfig

Providing a simple method of constructing a struct using struct tags and mapping them to runtime environmental variables

goconfig package uses the struct tag env to define the struct. For string slices you can define the separator with the tag sep

Example Struct

var Config struct {
Address         string   `env:"LISTEN_ADDRESS"`
Port            int      `env:"PORT"`
AllowedUsername []string `env:"ALLOWED_USERSNAMES"`
BootstapAdmins  []string `env:"BOOTSTRAP_ADMINS" sep:"||"`

PrivateRepo string `env:"PRIVATE_REPO"`
GoProxy     string `env:"GO_PROXY"`

ServerCertificatePath    string `env:"SERVER_CERTIFICATE_PATH"`
ServerCertificateKeyPath string `env:"SERVER_CERTIFICATE_KEY_PATH"`
ServerClientCABundlePath string `env:"SERVER_CLIENT_CA_BUNDLE_PATH"`

InsecureSkipVerify bool `env:"INSECURE_SKIP_VERIFY"`
}

Run env.Load inside an init function to preload environment variables to your Confg Struct from above

func init() {
if err := goconfig.Load(&Config); err != nil {
log.Fatal(err)
}

if Config.Port <= 0 {
Config.Port = 5050
}
//Set up defaults....
}

About

Providing a simple method of constructing a struct using struct tags and mapping them to runtime environmental variables

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages