Skip to content
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

Merged
merged 1 commit into from
Oct 14, 2022

Conversation

qwqcode
Copy link
Member

@qwqcode qwqcode commented Oct 14, 2022

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 依然未解决 😅😅😅😅😅😅

@qwqcode
Copy link
Member Author

qwqcode commented Oct 14, 2022

之后这一大堆东西可以删掉了,Golang 这个 Struct Tags 特性是真的恶心 😅😅😅😅😅😅

@qwqcode qwqcode merged commit 0fe3121 into master Oct 14, 2022
@qwqcode qwqcode deleted the fix/config branch October 14, 2022 12:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant