Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Viper – Go Configuration with Fangs (github.com/spf13)
10 points by maydemir on May 23, 2022 | hide | past | favorite | 3 comments


https://github.com/spf13/viper/blob/master/go.mod

16 direct dependencies, 39 transitive dependencies, and nearly 7000 lines of code -- for a package that handles flags and config files. I can't help feeling that frameworks like this are a little overwrought. It's the sort of project that succeeds because thousands of people just need something that works, right away, so they search for "golang config" and click the top result. Whereas if you can afford to slow down a little, you might find that the stdlib (with a bit of glue) is a perfectly serviceable option for the majority of apps.


I think any single feature isn't too difficult to replace with go's stdlib stuff. e.g. to read a flag, or read in a config file.

Viper has sophisticated functionality such that it might read a config file from one of several paths; the properties of which can be overridden with environment variables or command line flags.

With an emphasis on productivity, I think those mechanisms are useful, and probably not worth spending time to NIH from stdlib.


Use viper with care. It has some dangerous fundamental flaws [1]. We got bitten hard, submitted a PR [2] and followed up for a year and a half to no avail, before I went ahead and reinvented the wheel and wrote koanf (plug), specifically to avoid viper's flaws.

Most importantly:

- Breaks JSON, YAML, TOML etc. language specs by forcibly lowercasing all keys internally. Dangerous because it can silently merge differently cased config keys into lowercase.

- Hard codes big unnecessary dependencies into the core, significantly bloating build sizes. No separation or abstraction.

[1] https://github.com/spf13/viper/pull/635

[2] https://github.com/knadh/koanf#alternative-to-viper




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: