Skip to content

Library for loading configuration files (yaml, ...) into structs

License

Notifications You must be signed in to change notification settings

PRODYNA/goconfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goconfig

Library for loading configuration files (yaml, ...) into structs

Basic usage

Assuming you have a file called config.yaml in the default path

name: Hello

And a struct

type Configuration struct {
	Name string `yaml:"name"`
}

Load the yaml file into the struct

    cfg := &Configuration{}
    err := NewConfigLoader().LoadConfig( c)
    name := cfg.Name
    ...

Basic usage with env variables

Assuming you have a file called config.yaml in the default path and an exported environment variable MY_PWD = "secretvalue"

name: Hello
pwd: "{Env:MY_PWD}

And a struct

type Configuration struct {
	Name string `yaml:"name"`
	Pwd string  `yaml:"pwd"`
}

Load the yaml file into the struct

    cfg := &Configuration{}
    err := NewConfigLoader().LoadConfig( c)
    name := cfg.Name
    pwd := cfg.Pwd
    ...

Different paths

The default paths for searching a config file are

"", "k8s/dev/", "config/", "./config/", "/config/"

You can set the paths to new locations with:

    cfg := &Configuration{}
    err := NewConfigLoader().Paths("/mypath/").LoadConfig( c)
    name := cfg.Name
    pwd := cfg.Pwd
    ...

Different filename

The default filename for searching is

config.yaml

You can set the filename with:

    cfg := &Configuration{}
    err := NewConfigLoader().File("myownconfigfile.yml").LoadConfig( c)
    name := cfg.Name
    pwd := cfg.Pwd
    ...

About

Library for loading configuration files (yaml, ...) into structs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages