Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Props ¶
type Props interface {
// Add 用于将配置数据源 s,以优先级 priority,添加到 Props 对象中去.
Add(priority uint8, s Source) Source
// Find 函数尝试从多个配置数据源查找名字为 key 的配置项.
// 如果能够找到返回找到的配置项的值和true;否则,第二个返回值为false。
// 如果多个配置数据源都存在名字为 key 的配置项,那么以优先级最高的配置项为准。
// String、Int64、Uint64、Bool 等函数是对 Find 函数的简单封装。
Find(key string) (string, bool)
// String 尝试将找到的配置项以 string 的形式返回,如果找不到就返回 def.
String(key string, def string) string
// Int64 尝试将找到的配置项转换为 int64 的形式,如果找不到或者转换失败,就返回 def.
Int64(key string, def int64) int64
// Uint64 尝试将找到的配置项转换为 uint64 的形式,如果找不到或者转换失败,就返回 def.
Uint64(key string, def uint64) uint64
// Bool 尝试将找到的配置项转换为 bool 的形式,如果找不到或者转换失败,就返回 def.
// 当前支持的数据映射方式为:
// "1", "t", "T", "true", "TRUE", "True" 会被映射为 true;
// "0", "f", "F", "false", "FALSE", "False" 会被映射为 false。
// 如果配置项的值为其他的值,作为转换失败处理。
Bool(key string, def bool) bool
// 将字符串 s 中的所有 ${key} 形式的可扩展变量,替换为本 Props 对象内部的配置项 key 的值,并最终返回替换后的结果.
// 如果某个 key 的配置项在 Props 对象中不存在,将原样保留 ${key};
// 如果某个 key 的配置项的值里面还含有 ${xxx},那么也会自动展开;
// 如果变量存在循环引用现象,返回失败;
Expand(s string) (string, error)
}
Props 定义了配置数据的操作集合. 该接口提供了添加配置数据源,配置项查找,配置项读取,使用配置项扩展变量等多个函数.
type SourceCustom ¶
type SourceCustom struct {
// contains filtered or unexported fields
}
SourceCustom 表示用户自定义的配置数据源.
func NewSourceCustom ¶
func NewSourceCustom() *SourceCustom
NewSourceCustom 创建一个 SourceCustom 的数据源对象.
func (SourceCustom) Find ¶
func (s SourceCustom) Find(key string) (string, bool)
Find 为 Source 的接口实现,具体功能参见 `Source`.
func (*SourceCustom) Set ¶
func (s *SourceCustom) Set(key string, val string)
Set 用于将 key 和 value 放入 SourceCustom 对象中,方便后续通过 Props 的接口获取.
type SourceProperties ¶
type SourceProperties struct {
// contains filtered or unexported fields
}
func NewSourceProperties ¶
func NewSourceProperties() *SourceProperties
func (*SourceProperties) LoadFile ¶
func (s *SourceProperties) LoadFile(filename string) error
Click to show internal directories.
Click to hide internal directories.