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

Define defaults using viper.SetDefault #208

Closed
sagikazarmark opened this issue Oct 27, 2020 · 4 comments
Closed

Define defaults using viper.SetDefault #208

sagikazarmark opened this issue Oct 27, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@sagikazarmark
Copy link
Contributor

I noticed a slight issue around configuration. Namely: if the config file containing defaults is missing, environment variables are not recognized.

The root cause of this issue is this: spf13/viper#761

Basically, AutomaticEnv doesn't work with Unmarshal when the keys that env vars are mapped to does not already exist in Viper via some other way. AutomaticEnv tries to look for those keys in environment variables when unmarshaling values on a struct.

I recommend using SetDefault to set default values (even empty ones), so that the config file does not have to contain all default/empty values for sftpgo to work.

@drakkan
Copy link
Owner

drakkan commented Oct 27, 2020

Hi,

I am aware of this issue, see here basically you have to ship the default config file if you want to use env vars, as we do for example with the docker image.

I was hoping it would be fixed in viper .. :)

Maybe I could use something like this

@sagikazarmark
Copy link
Contributor Author

I was hoping it would be fixed in viper .. :)

It's not likely to be fixed in the near future :\ Mostly because it's not trivial to fix and all the potential solutions have their own downsides.

As far as I can tell, you already set defaults. Not in Viper, but in the global struct directly. So instead of doing that, you could just set the defaults in Viper. :)

@drakkan
Copy link
Owner

drakkan commented Oct 27, 2020

I was hoping it would be fixed in viper .. :)

It's not likely to be fixed in the near future :\ Mostly because it's not trivial to fix and all the potential solutions have their own downsides.

As far as I can tell, you already set defaults. Not in Viper, but in the global struct directly. So instead of doing that, you could just set the defaults in Viper. :)

I would like to avoid to manually set the defaults in viper, it is error prone since I have to write both the key and the value manually, I'll eventually try one the wrapper suggested on the linked viper bug

@sagikazarmark
Copy link
Contributor Author

Either way, tests should probably make sure of the correct behavior.

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

Successfully merging a pull request may close this issue.

2 participants