This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
fix(config): replace viper with koanf to make map case sensitivity #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Viper 是一个 Golang 的配置文件读取工具,它能够帮助读取 yaml、json 等格式的配置文件到一个 go struct
但 Viper 读取配置文件的配置项目 keys 的策略是将每个 key 转为全小写的形式,它是 case insensitive 的:
https://github.com/spf13/viper#does-viper-support-case-sensitive-keys
虽然这样设计存在它的合理性。
但是,由于 frontend 配置中每一项的 key 有保留原本大小写的需要,因为前端配置的 keys 是驼峰命名法 (Camel-Case),所以不得不将配置文件的 keys 原封不动地读取出来提供给前端
Viper 对于 keys 大小写不敏感,故弃用转而使用 koanf
关联
对于大小写敏感性这个问题 2016 年就存在,直到现在 2022 年底 viper 依然未解决 😅😅😅😅😅😅