Documentation ¶
Index ¶
- Constants
- func Fill(prop Properties, result interface{}) error
- func FillEx(prop Properties, result interface{}, withField bool) error
- func FillExWithTagName(prop Properties, result interface{}, withField bool, tagPxName, tagName string) error
- func FillExWithTagNames(prop Properties, result interface{}, withField bool, ...) error
- func GetBool(props Properties) func(key string, defaultValue bool) bool
- func GetEnvs() map[string]string
- func GetFloat32(props Properties) func(key string, defaultValue float32) float32
- func GetFloat64(props Properties) func(key string, defaultValue float64) float64
- func GetInt(props Properties) func(key string, defaultValue int) int
- func GetInt64(props Properties) func(key string, defaultValue int64) int64
- func GetString(props Properties) func(key string, defaultValue string) string
- func GetUint(props Properties) func(key string, defaultValue uint) uint
- func GetUint64(props Properties) func(key string, defaultValue uint64) uint64
- func SetLog(log logFunc)
- type DefaultProperties
- func (ctx *DefaultProperties) ExecTemplate(r io.Reader) (io.Reader, error)
- func (ctx *DefaultProperties) Get(key string, defaultValue string) string
- func (ctx *DefaultProperties) GetValue(key string, result interface{}) error
- func (ctx *DefaultProperties) ReadValue(r io.Reader) error
- func (ctx *DefaultProperties) SetValueLoader(l ValueLoader)
- func (ctx *DefaultProperties) SetValueReader(r ValueReader)
- type Deserializer
- type Errors
- type JsonLoader
- type JsonReader
- type Opt
- type Properties
- type Serializer
- type SettableProperties
- type Value
- type ValueLoader
- type ValueReader
- type YamlLoader
- type YamlReader
Constants ¶
View Source
const ( TagPrefixName = "figPx" TagName = "fig" )
Variables ¶
This section is empty.
Functions ¶
func Fill ¶
func Fill(prop Properties, result interface{}) error
param: prop 属性 param: result 填充的struct result: result如果不为struct的指针返回错误,填充时异常返回错误
func FillEx ¶ added in v0.0.2
func FillEx(prop Properties, result interface{}, withField bool) error
param: prop 属性 param: result 填充的struct param: withField 是否根据field name填充 result: result如果不为struct的指针返回错误,填充时异常返回错误
func FillExWithTagName ¶ added in v0.0.3
func FillExWithTagName(prop Properties, result interface{}, withField bool, tagPxName, tagName string) error
param: prop 属性 param: result 填充的struct param: withField 是否根据field name填充 param: tagPxName tag前缀名,后续都使用tagPxName定义的名称做前缀 param: tagName tag名 result: result如果不为struct的指针返回错误,填充时异常返回错误
func FillExWithTagNames ¶ added in v0.1.3
func FillExWithTagNames(prop Properties, result interface{}, withField bool, tagPxNames, tagNames []string) error
param: prop 属性 param: result 填充的struct param: withField 是否根据field name填充 param: tagPxNames tag前缀名,后续都使用tagPxName定义的名称做前缀 param: tagNames tag名 result: result如果不为struct的指针返回错误,填充时异常返回错误
func GetFloat32 ¶
func GetFloat32(props Properties) func(key string, defaultValue float32) float32
func GetFloat64 ¶
func GetFloat64(props Properties) func(key string, defaultValue float64) float64
Types ¶
type DefaultProperties ¶
type DefaultProperties struct { Value *Value Env map[string]string // contains filtered or unexported fields }
func New ¶
func New(opts ...Opt) *DefaultProperties
func (*DefaultProperties) ExecTemplate ¶
func (*DefaultProperties) Get ¶
func (ctx *DefaultProperties) Get(key string, defaultValue string) string
A.B.C
func (*DefaultProperties) GetValue ¶
func (ctx *DefaultProperties) GetValue(key string, result interface{}) error
依赖于ValueReader的序列化和反序列化方式
func (*DefaultProperties) ReadValue ¶ added in v0.1.1
func (ctx *DefaultProperties) ReadValue(r io.Reader) error
func (*DefaultProperties) SetValueLoader ¶ added in v0.1.1
func (ctx *DefaultProperties) SetValueLoader(l ValueLoader)
func (*DefaultProperties) SetValueReader ¶
func (ctx *DefaultProperties) SetValueReader(r ValueReader)
type Deserializer ¶ added in v0.1.1
type JsonLoader ¶ added in v0.1.1
type JsonLoader struct{}
func NewJsonLoader ¶ added in v0.1.1
func NewJsonLoader() *JsonLoader
func (*JsonLoader) Deserialize ¶ added in v0.1.1
func (v *JsonLoader) Deserialize(value string, result interface{}) error
func (*JsonLoader) Serialize ¶ added in v0.1.1
func (v *JsonLoader) Serialize(o interface{}) (string, error)
type Opt ¶
type Opt func(ctx *DefaultProperties) error
func SetValueLoader ¶ added in v0.1.1
func SetValueLoader(l ValueLoader) Opt
func SetValueReader ¶
func SetValueReader(r ValueReader) Opt
type Properties ¶
type Properties interface { // 配置ValueReader SetValueReader(r ValueReader) // 读取value ReadValue(r io.Reader) error // 设置ValueLoader值提取器 SetValueLoader(l ValueLoader) // param: key属性名称 // param: defaultValue: 默认值 // return: 属性值,如不存在返回默认值 Get(key string, defaultValue string) string // param: key属性名称 // param: result: 填充对象指针 // return: 正常返回nil,否则返回错误 GetValue(key string, result interface{}) error }
var Default Properties = New()
func LoadFile ¶
func LoadFile(filename string, reader ValueReader, loader ValueLoader) (Properties, error)
func LoadJsonFile ¶
func LoadJsonFile(filename string) (Properties, error)
func LoadYamlFile ¶
func LoadYamlFile(filename string) (Properties, error)
func MergeProperties ¶ added in v0.1.1
func MergeProperties(props ...Properties) Properties
type Serializer ¶ added in v0.1.1
type SettableProperties ¶ added in v0.1.1
type SettableProperties struct {
DefaultProperties
}
func NewSettableProperties ¶ added in v0.1.1
func NewSettableProperties(opts ...Opt) *SettableProperties
func (*SettableProperties) Delete ¶ added in v0.1.1
func (p *SettableProperties) Delete(key string)
func (*SettableProperties) Set ¶ added in v0.1.1
func (p *SettableProperties) Set(key string, value interface{}) error
type ValueLoader ¶ added in v0.1.1
type ValueLoader interface { Serializer Deserializer }
type YamlLoader ¶ added in v0.1.1
type YamlLoader struct{}
func NewYamlLoader ¶ added in v0.1.1
func NewYamlLoader() *YamlLoader
func (*YamlLoader) Deserialize ¶ added in v0.1.1
func (v *YamlLoader) Deserialize(value string, result interface{}) error
func (*YamlLoader) Serialize ¶ added in v0.1.1
func (v *YamlLoader) Serialize(o interface{}) (string, error)
Click to show internal directories.
Click to hide internal directories.