-
Notifications
You must be signed in to change notification settings - Fork 0
xconf
omeyang edited this page Sep 17, 2026
·
1 revision
稳定性:Stable · 覆盖率:92.0% · 源码:
pkg/config/xconf
配置管理。基于 koanf,支持文件 / 环境变量 / 命令行 / 远程多源合并。
- 应用启动加载配置(YAML/TOML/JSON)
- 多环境覆盖(base + override)
- 热加载(部分后端)
- 不引入 viper(依赖太重)
import "github.com/omeyang/xkit/pkg/config/xconf"
c, err := xconf.New(
xconf.WithFile("config.yaml"),
xconf.WithEnv("MYAPP_"),
)
if err != nil { /* ... */ }
var cfg struct {
Listen string
DB struct{ DSN string }
}
_ = c.Unmarshal("", &cfg)| 名称 | 说明 |
|---|---|
Config interface |
Client() *koanf.Koanf / Unmarshal(path, target) |
New(opts...) (Config, error) |
入口 |
WithFile / WithEnv / WithRemote |
后端注入 |
-
Reset/Init/InitWith顺序保证:先写值再标志,避免读到未初始化状态 -
dt==""注释明确允许(doc.go:L231-233)
- 包:xenv(直接读 ENV 的简化场景)
- API:api.md#pkgconfigxconf