'Validating configurations files with viper
I was looking for a configuration parser for go and https://github.com/spf13/viper seems to come highly recommended.
I am very surprised to find that configuration files are not validated by default. Viper parses files and extracts requested values from them but I cannot find a way to detect bad configuration.
For instance I if create a (Java style) .properties file containing just "???" and nothing else. This is accepted without any error.
I can understand the philosophy that you should ignore irrelevant configuration items but I desire more rigor. I would also like to reject anything that does not match the X=Y format in a properties file.
To me this is a fatal flaw that suggests I should use a different package (or roll my own as usual).
Have I missed something? Does viper in fact support detecting and rejecting bad configuration keys?
Solution 1:[1]
I think the answer is no. viper does not validate java .properties files. I posted a bug report (or feature request depending on your point of view) as https://github.com/spf13/viper/issues/790
Solution 2:[2]
You can try https://github.com/num30/config library which is based on Viper. It has built-in validation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bruce Adams |
Solution 2 | Denis Palnitsky |