Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to envconfig for configuration #284

Closed
arschles opened this issue Jul 17, 2018 · 5 comments · Fixed by #627
Closed

switch to envconfig for configuration #284

arschles opened this issue Jul 17, 2018 · 5 comments · Fixed by #627

Comments

@arschles
Copy link
Member

the ./pkg/config/env package has lots and lots of envy.Get (and friends) calls, with defaults, type conversions, etc...

let's remove all that duplicated code and use envconfig

@marwan-at-work
Copy link
Contributor

@arschles Should we have a config struct with all of our expected environment variables?

@ghost
Copy link

ghost commented Jul 26, 2018

I think so @marwan-at-work. What do you think about using an init to first load the config, then the subsequent calls can return needed variables?

@michalpristas
Copy link
Member

👍 for a configuration file. keep dev defaults there. we can inject/replace the file with test/prod env easily on deploy

@marwan-at-work
Copy link
Contributor

marwan-at-work commented Aug 5, 2018

What about having a json or toml representation of that config struct and so instead of populating env variables and keeping track of them, we just have one file where all this stuff lives.
Something like this

type Config struct {
  GoBinPath string
  OlympusGlobalURL string
  DebugLevel string
  ...
}

And then we can have several json representations for different environments:

config.local.json

{
  "GoBinPath": "go",
  "OlympusGlobalURL": "http://localhost:3001",
  "DebugLevel": "debug"
}

and then config.prod.json

{
  "GoBinPath": "go",
  "OlympusGlobalURL": "https://www.olympus.com",
  "DebugLevel": "warning"
}

This way we don't need envconfig, or we can use it for overrides in the config if we really want to. Which is cool w/ me.

We can also use https://github.com/go-playground/validator to validate that some Config fields are required as such

type Config struct {
  GoBinPath string `validate:"required"` 
  OlympusGlobalURL string `env:"OLYMPUS_GLOBAL_URL"`
  DebugLevel string
  ...
}

@rohancme
Copy link
Contributor

rohancme commented Aug 6, 2018

I'll work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants