Bruce Adams
Bruce Adams

Reputation: 5589

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?

Upvotes: 1

Views: 3825

Answers (2)

Denis Palnitsky
Denis Palnitsky

Reputation: 18387

You can try https://github.com/num30/config library which is based on Viper. It has built-in validation.

Upvotes: 0

Bruce Adams
Bruce Adams

Reputation: 5589

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

Upvotes: 1

Related Questions