Documentation ¶
Index ¶
- Variables
- func Cast(name string, fn TypeConversionFunc) (interface{}, bool)
- func CastOrDefault(name string, defaultValue interface{}, fn TypeConversionFunc) interface{}
- func CombinePath(pathSegments ...string) string
- func ExtractMap(data interface{}, path string) map[string]*ExtractedValue
- func ExtractStructToMap(data interface{}, path string) map[string]*ExtractedValue
- func GetConfiguration(providers []Provider, name string) (string, bool)
- func GetParentPath(path string) (string, bool)
- func GetSectionKey(path string) string
- func GetString(name string) (string, bool)
- func GetStringOrDefault(name string, defaultValue string) string
- func Init(fn func(Builder))
- func Segment(key string, prefixLength int) string
- type Builder
- type Configuration
- type ConfigurationBuilder
- type ConfigurationProvider
- func (provider *ConfigurationProvider) GetChildKeys(path string, earlierKeys ...string) []string
- func (provider *ConfigurationProvider) GetExtracted(name string) (*ExtractedValue, bool)
- func (provider *ConfigurationProvider) GetString(name string) (string, bool)
- func (provider *ConfigurationProvider) Load() error
- type ConfigurationRoot
- func (root *ConfigurationRoot) GetChildren() []Section
- func (root *ConfigurationRoot) GetExtracted(name string) (*ExtractedValue, bool)
- func (root *ConfigurationRoot) GetProviders() []Provider
- func (root *ConfigurationRoot) GetSection(name string) Section
- func (root *ConfigurationRoot) GetString(name string) (string, bool)
- func (root *ConfigurationRoot) Reload() error
- type ConfigurationSection
- func (section *ConfigurationSection) Bind(recv interface{}) error
- func (section *ConfigurationSection) GetChildren() []Section
- func (section *ConfigurationSection) GetExtracted(name string) (*ExtractedValue, bool)
- func (section *ConfigurationSection) GetName() string
- func (section *ConfigurationSection) GetPath() string
- func (section *ConfigurationSection) GetRaw() (interface{}, bool)
- func (section *ConfigurationSection) GetSection(name string) Section
- func (section *ConfigurationSection) GetString(name string) (string, bool)
- func (section *ConfigurationSection) GetValue() (string, bool)
- type ExtractedValue
- type MemoryProvider
- type MemorySource
- type Provider
- type Root
- type Section
- type Source
- type TypeConversionFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var KeyDelimiter = "."
Functions ¶
func Cast ¶
func Cast(name string, fn TypeConversionFunc) (interface{}, bool)
func CastOrDefault ¶
func CastOrDefault(name string, defaultValue interface{}, fn TypeConversionFunc) interface{}
func CombinePath ¶
Combine paths to one path with KeyDelimiter
func ExtractMap ¶
func ExtractMap(data interface{}, path string) map[string]*ExtractedValue
func ExtractStructToMap ¶
func ExtractStructToMap(data interface{}, path string) map[string]*ExtractedValue
func GetStringOrDefault ¶
Types ¶
type Builder ¶
type Builder interface { Properties() map[string]interface{} Sources() []Source AddSource(source Source) Builder BuildRoot() Root }
func NewBuilder ¶
func NewBuilder() Builder
type Configuration ¶
type ConfigurationBuilder ¶
type ConfigurationBuilder struct {
// contains filtered or unexported fields
}
func (*ConfigurationBuilder) AddSource ¶
func (builder *ConfigurationBuilder) AddSource(source Source) Builder
func (*ConfigurationBuilder) BuildRoot ¶
func (builder *ConfigurationBuilder) BuildRoot() Root
func (*ConfigurationBuilder) Properties ¶
func (builder *ConfigurationBuilder) Properties() map[string]interface{}
func (*ConfigurationBuilder) Sources ¶
func (builder *ConfigurationBuilder) Sources() []Source
type ConfigurationProvider ¶
type ConfigurationProvider struct {
Data map[string]*ExtractedValue
}
func NewConfigurationProvider ¶
func NewConfigurationProvider() *ConfigurationProvider
func (*ConfigurationProvider) GetChildKeys ¶
func (provider *ConfigurationProvider) GetChildKeys(path string, earlierKeys ...string) []string
基于此返回给定父路径的直接后代配置键
func (*ConfigurationProvider) GetExtracted ¶
func (provider *ConfigurationProvider) GetExtracted(name string) (*ExtractedValue, bool)
func (*ConfigurationProvider) GetString ¶
func (provider *ConfigurationProvider) GetString(name string) (string, bool)
尝试获取一个配置key的值
func (*ConfigurationProvider) Load ¶
func (provider *ConfigurationProvider) Load() error
type ConfigurationRoot ¶
type ConfigurationRoot struct {
Providers []Provider
}
func NewRoot ¶
func NewRoot(providers []Provider) *ConfigurationRoot
func (*ConfigurationRoot) GetChildren ¶
func (root *ConfigurationRoot) GetChildren() []Section
func (*ConfigurationRoot) GetExtracted ¶
func (root *ConfigurationRoot) GetExtracted(name string) (*ExtractedValue, bool)
func (*ConfigurationRoot) GetProviders ¶
func (root *ConfigurationRoot) GetProviders() []Provider
func (*ConfigurationRoot) GetSection ¶
func (root *ConfigurationRoot) GetSection(name string) Section
func (*ConfigurationRoot) GetString ¶
func (root *ConfigurationRoot) GetString(name string) (string, bool)
func (*ConfigurationRoot) Reload ¶
func (root *ConfigurationRoot) Reload() error
type ConfigurationSection ¶
type ConfigurationSection struct {
// contains filtered or unexported fields
}
func NewSection ¶
func NewSection(root Root, path string) *ConfigurationSection
func (*ConfigurationSection) Bind ¶
func (section *ConfigurationSection) Bind(recv interface{}) error
func (*ConfigurationSection) GetChildren ¶
func (section *ConfigurationSection) GetChildren() []Section
func (*ConfigurationSection) GetExtracted ¶
func (section *ConfigurationSection) GetExtracted(name string) (*ExtractedValue, bool)
func (*ConfigurationSection) GetName ¶
func (section *ConfigurationSection) GetName() string
func (*ConfigurationSection) GetPath ¶
func (section *ConfigurationSection) GetPath() string
func (*ConfigurationSection) GetRaw ¶
func (section *ConfigurationSection) GetRaw() (interface{}, bool)
func (*ConfigurationSection) GetSection ¶
func (section *ConfigurationSection) GetSection(name string) Section
func (*ConfigurationSection) GetString ¶
func (section *ConfigurationSection) GetString(name string) (string, bool)
func (*ConfigurationSection) GetValue ¶
func (section *ConfigurationSection) GetValue() (string, bool)
type ExtractedValue ¶
func GetConfigExtractedValue ¶
func GetConfigExtractedValue(providers []Provider, name string) (*ExtractedValue, bool)
func NewExtractedValue ¶
func NewExtractedValue(name string, value string, raw interface{}) *ExtractedValue
type MemoryProvider ¶
type MemoryProvider struct { ConfigurationProvider // contains filtered or unexported fields }
func NewMemoryProvider ¶
func NewMemoryProvider(source *MemorySource) *MemoryProvider
func (*MemoryProvider) Add ¶
func (provider *MemoryProvider) Add(key, value string)
type MemorySource ¶
func EnvironmentVariable ¶
func EnvironmentVariable(prefix string) *MemorySource
func Memory ¶
func Memory(initialData map[string]string) *MemorySource
func (*MemorySource) BuildProvider ¶
func (source *MemorySource) BuildProvider(builder Builder) Provider
type Root ¶
type Root interface { Configuration Reload() error GetProviders() []Provider }
func ConfigRoot ¶
func ConfigRoot() Root
type Section ¶
type Section interface { Configuration GetName() string GetPath() string GetValue() (string, bool) GetRaw() (interface{}, bool) Bind(recv interface{}) error }
func GetChildrenFromRoot ¶
func GetSection ¶
type TypeConversionFunc ¶
var ( IntConversion TypeConversionFunc = func(s string) (interface{}, error) { v, err := strconv.ParseFloat(s, 64) if err != nil { return nil, err } return int(v), nil } FloatConversion TypeConversionFunc = func(s string) (interface{}, error) { v, err := strconv.ParseFloat(s, 64) if err != nil { return nil, err } return v, nil } BooleanConversion TypeConversionFunc = func(s string) (interface{}, error) { v, err := strconv.ParseFloat(s, 64) if err != nil { return strings.ToLower(s) == "true", nil } return v > 0, nil } )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.