Documentation
¶
Overview ¶
Package config 提供 dscli 配置管理,包括全局配置目录 (~/.dscli) 和项目级 .dscli/ 目录的初始化工。
Package conf supports a configuration file format used by gnatsd. It is a flexible format that combines the best of traditional configuration formats and newer styles such as JSON and YAML.
Index ¶
- Variables
- func EnsureProjectGitignore(projectRoot string) error
- func Get(name, defaultValue string, alias ...string) string
- func GetBool(name string, defaultValue bool, alias ...string) bool
- func GetInt(name string, defaultValue int, alias ...string) int
- func GetValue(name string) any
- func Parse(data string) (map[string]any, error)
- func ParseFile(fp string) (map[string]any, error)
- func ParseFileWithChecks(fp string) (map[string]any, error)
- func ParseFileWithChecksDigest(fp string) (map[string]any, string, error)
- func ParseWithChecks(data string) (map[string]any, error)
- func Set(name, value string)
- func SetValue(name string, value any)
- type Config
Constants ¶
This section is empty.
Variables ¶
var ( // BuildTime is set via ldflags at build time, e.g. // -X github.com/dscli/dscli/internal/config.BuildTime=2026-05-20T08:00:00Z BuildTime string )
var ConfigDir = func() string {
return getGlobalConfig().ConfigDir()
}()
ConfigDir 配置目录(向后兼容变量) 注意:这是一个函数调用,返回配置目录路径
Functions ¶
func EnsureProjectGitignore ¶ added in v0.8.6
EnsureProjectGitignore 确保项目级 .dscli/.gitignore 存在。
projectRoot 是项目的根目录(通常为 context.ProjectRoot)。
策略:
- 仅当 .dscli/ 目录已存在时工作(不因创建 .gitignore 而反创建父目录)
- 如果 .gitignore 已存在,跳过(保留用户自定义修改)
- 幂等,可安全重复调用
func GetBool ¶
支持 strconv.ParseBool 的格式:1/t/T/TRUE/true/True → true,0/f/F/FALSE/false/False → false 未配置或解析失败时返回 defaultValue
func Parse ¶ added in v0.8.8
Parse will return a map of keys to any, although concrete types underly them. The values supported are string, bool, int64, float64, DateTime. Arrays and nested Maps are also supported.
func ParseFileWithChecks ¶ added in v0.8.8
ParseFileWithChecks is equivalent to ParseFile but runs in pedantic mode.
func ParseFileWithChecksDigest ¶ added in v0.8.8
ParseFileWithChecksDigest returns the processed config and a digest that represents the configuration.
func ParseWithChecks ¶ added in v0.8.8
ParseWithChecks is equivalent to Parse but runs in pedantic mode.