Skip to content

cloudcarver/edc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EDC (Extremely Dope Code)

Conf

Read config from configuration file OR from environment variables, then unmarshal it into a struct.

  1. You can use config file to set up your application. This step is optional.

    pg:
        host: 127.0.0.1
        port: 5432
    secret:
        authorizedKey: "key"
  2. Use FetchConfig to load the config file.

    import "github.com/cloudcarver/edc/conf"
    
    type PG struct {
        Host string `yaml:"host"`
        Port int    `yaml:"port"`
    }
    
    type Secret struct {
        AuthorizedKey string `yaml:"authorizedKey"`
    }
    
    type Config struct {
        PG     PG     `yaml:"pg"`
        Secret Secret `yaml:"secret"`
    }
    
    func main() {
        config := Config{}
        err := conf.FetchConfig("conf.yaml", "MYAPP", &config)
        if err != nil {
            panic(err)
        }
        ...
    }
  3. Start the application.

    MYAPP_PG_HOST=myapp.local go run main.go

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages