Documentation
¶
Index ¶
- func GetConfStrByLine(line string) (itemk, itemv string)
- type Conf
- func (cf *Conf) AddComment(title string, comment ...string)
- func (cf *Conf) BoolVar(pval *bool, name string, defval bool, title string, usage ...string)
- func (cf Conf) DefaultString() string
- func (cf *Conf) Float64Var(pval *float64, name string, defval float64, title string, usage ...string)
- func (cf *Conf) IntListVar(pval *[]int, name string, defval []int, title string, usage ...string)
- func (cf *Conf) IntVar(pval *int, name string, defval int, title string, usage ...string)
- func (cf *Conf) Parse(flagParse bool) error
- func (cf *Conf) SetValuesByCmdArgs() []error
- func (cf *Conf) SetValuesByEnv() error
- func (cf *Conf) SetValuesByEnvFile(envfile string)
- func (cf Conf) String() string
- func (cf *Conf) StringListVar(pval *[]string, name string, defval []string, title string, usage ...string)
- func (cf *Conf) StringVar(pval *string, name string, defval, title string, usage ...string)
- func (cf *Conf) UpdateFile(fpath string) error
- type ConfItem
- type JsonConf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfStrByLine ¶
GetConfStrByLine 从单行字符串中提取配置项的键值对字符串
Types ¶
type Conf ¶
type Conf struct {
// contains filtered or unexported fields
}
func (*Conf) AddComment ¶
func (*Conf) Float64Var ¶
func (*Conf) IntListVar ¶
func (*Conf) Parse ¶
Parse 从配置文件和系统环境变量解析配置。 如flagParse为true,还会从命令行参数解析配置。但会和原生的flag.Parse()冲突。 其他地方还有调用flag.Parse()的代码,应删除,由本方法统一调用。
func (*Conf) SetValuesByCmdArgs ¶ added in v1.2.0
SetValuesByCmdArgs 从命令行参数获取配置。优先级高 允许设置值为空字符串。
func (*Conf) SetValuesByEnv ¶ added in v1.2.0
SetValuesByEnv 从操作系统的环境变量获取配置。优先级中 配置值为空字符串会被忽略
func (*Conf) SetValuesByEnvFile ¶ added in v1.2.0
SetValuesByEnvFile 从env配置文件更新配置项。优先级低。 配置值为空字符串会被忽略
func (*Conf) StringListVar ¶
func (*Conf) UpdateFile ¶
type ConfItem ¶
type ConfItem struct {
Name string // 配置项键名。键名为空字符串,则该项的值可能为注释。
Title string
ValueStr string // 配置项的字符串原始值。对于只有字符串类型的环境变量很有用。
Value any // 配置项的值,类型为指针,引用传递。
DefaultValue any // 配置项的默认值,值传递。
Usage []string
}
ConfItem 配置项信息。 包含配置名,标题,配置值,默认值,使用说明。
func (ConfItem) DefaultString ¶
func (ConfItem) GetDefaultValue ¶
type JsonConf ¶ added in v1.1.3
type JsonConf struct {
// contains filtered or unexported fields
}
JsonConf 以 JSON 文件格式保存和读取配置
func NewJsonConf ¶ added in v1.1.3
NewJsonConf 创建 JsonConf 实例,dirPath 为配置文件存放目录
Source Files
¶
Click to show internal directories.
Click to hide internal directories.