Documentation ¶
Index ¶
- Constants
- Variables
- func Apply(conf map[string]interface{}) error
- func Debug(sep string)
- func Exists(key string) bool
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetDuration(key string) time.Duration
- func GetFloat64(key string) float64
- func GetInt(key string) int
- func GetInt64(key string) int64
- func GetInt64Slice(key string) []int64
- func GetSlice(key string) []interface{}
- func GetString(key string) string
- func GetStringMap(key string) map[string]interface{}
- func GetStringMapString(key string) map[string]string
- func GetStringMapStringSlice(key string) map[string][]string
- func GetStringSlice(key string) []string
- func GetTime(key string) time.Time
- func LoadFromDataSource(ds DataSource, unmarshaller Unmarshaller) error
- func LoadFromReader(r io.Reader, unmarshaller Unmarshaller) error
- func OnChange(fn func(*Configuration))
- func OnLoaded(fn func(*Configuration))
- func Register(scheme string, creator DataSourceCreatorFunc)
- func Reset()
- func Set(key string, val interface{})
- func Traverse(sep string) map[string]interface{}
- func UnmarshalKey(key string, rawVal interface{}, opts ...GetOption) error
- func UnmarshalWithExpect(key string, expect interface{}) interface{}
- type Configuration
- func (c *Configuration) Get(key string) interface{}
- func (c *Configuration) GetBool(key string) bool
- func (c *Configuration) GetDuration(key string) time.Duration
- func (c *Configuration) GetFloat64(key string) float64
- func (c *Configuration) GetInt(key string) int
- func (c *Configuration) GetInt64(key string) int64
- func (c *Configuration) GetInt64Slice(key string) []int64
- func (c *Configuration) GetSlice(key string) []interface{}
- func (c *Configuration) GetString(key string) string
- func (c *Configuration) GetStringMap(key string) map[string]interface{}
- func (c *Configuration) GetStringMapString(key string) map[string]string
- func (c *Configuration) GetStringMapStringSlice(key string) map[string][]string
- func (c *Configuration) GetStringSlice(key string) []string
- func (c *Configuration) GetTime(key string) time.Time
- func (c *Configuration) Load(content []byte, unmarshal Unmarshaller) error
- func (c *Configuration) LoadEnvironments(prefix string)
- func (c *Configuration) LoadFromDataSource(ds DataSource, unmarshaller Unmarshaller) error
- func (c *Configuration) LoadFromReader(reader io.Reader, unmarshaller Unmarshaller) error
- func (c *Configuration) OnChange(fn func(*Configuration))
- func (c *Configuration) OnLoaded(fn func(*Configuration))
- func (c *Configuration) Set(key string, val interface{}) error
- func (c *Configuration) SetKeyDelim(delim string)
- func (c *Configuration) Sub(key string) *Configuration
- func (c *Configuration) UnmarshalKey(key string, rawVal interface{}, opts ...GetOption) error
- func (c *Configuration) UnmarshalWithExpect(key string, expect interface{}) interface{}
- func (c *Configuration) WriteConfig() error
- type DataSource
- type DataSourceCreatorFunc
- type GetOption
- type GetOptions
- type Unmarshaller
Constants ¶
const DefaultEnvPrefix = "APP_"
Variables ¶
var ( //ErrConfigAddr not config ErrConfigAddr = errors.New("no config... ") // ErrInvalidDataSource defines an error that the scheme has been registered ErrInvalidDataSource = errors.New("invalid data source, please make sure the scheme has been registered") )
var ErrInvalidKey = errors.New("invalid key, maybe not exist in config")
ErrInvalidKey ...
Functions ¶
func Get ¶
func Get(key string) interface{}
Get returns an interface. For a specific value use one of the Get____ methods.
func GetBool ¶
GetBool returns the value associated with the key as a boolean with default defaultConfiguration.
func GetDuration ¶
GetDuration returns the value associated with the key as a duration with default defaultConfiguration.
func GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64 with default defaultConfiguration.
func GetInt ¶
GetInt returns the value associated with the key as an integer with default defaultConfiguration.
func GetInt64 ¶
GetInt64 returns the value associated with the key as an integer with default defaultConfiguration.
func GetInt64Slice ¶
GetInt64Slice returns the value associated with the key as an integer slice with default defaultConfiguration.
func GetSlice ¶
func GetSlice(key string) []interface{}
GetSlice returns the value associated with the key as a slice of strings with default defaultConfiguration.
func GetString ¶
GetString returns the value associated with the key as a string with default defaultConfiguration.
func GetStringMap ¶
GetStringMap returns the value associated with the key as a map of interfaces with default defaultConfiguration.
func GetStringMapString ¶
GetStringMapString returns the value associated with the key as a map of strings with default defaultConfiguration.
func GetStringMapStringSlice ¶
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings with default defaultConfiguration.
func GetStringSlice ¶
GetStringSlice returns the value associated with the key as a slice of strings with default defaultConfiguration.
func GetTime ¶
GetTime returns the value associated with the key as time with default defaultConfiguration.
func LoadFromDataSource ¶
func LoadFromDataSource(ds DataSource, unmarshaller Unmarshaller) error
LoadFromDataSource load configuration from data source if data source supports dynamic config, a monitor goroutinue would be
func LoadFromReader ¶
func LoadFromReader(r io.Reader, unmarshaller Unmarshaller) error
Load loads configuration from provided provider with default defaultConfiguration.
func OnLoaded ¶
func OnLoaded(fn func(*Configuration))
func Register ¶
func Register(scheme string, creator DataSourceCreatorFunc)
Register registers a dataSource creator function to the registry
func UnmarshalKey ¶
UnmarshalKey takes a single key and unmarshal it into a Struct with default defaultConfiguration.
func UnmarshalWithExpect ¶
func UnmarshalWithExpect(key string, expect interface{}) interface{}
UnmarshalWithExpect unmarshal key, returns expect if failed
Types ¶
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration provides configuration for application.
func (*Configuration) Get ¶
func (c *Configuration) Get(key string) interface{}
Get returns the value associated with the key
func (*Configuration) GetBool ¶
func (c *Configuration) GetBool(key string) bool
GetBool returns the value associated with the key as a boolean.
func (*Configuration) GetDuration ¶
func (c *Configuration) GetDuration(key string) time.Duration
GetDuration returns the value associated with the key as a duration.
func (*Configuration) GetFloat64 ¶
func (c *Configuration) GetFloat64(key string) float64
GetFloat64 returns the value associated with the key as a float64.
func (*Configuration) GetInt ¶
func (c *Configuration) GetInt(key string) int
GetInt returns the value associated with the key as an integer.
func (*Configuration) GetInt64 ¶
func (c *Configuration) GetInt64(key string) int64
GetInt64 returns the value associated with the key as an integer.
func (*Configuration) GetInt64Slice ¶
func (c *Configuration) GetInt64Slice(key string) []int64
GetInt64Slice returns the value associated with the key as an integer slice.
func (*Configuration) GetSlice ¶
func (c *Configuration) GetSlice(key string) []interface{}
GetSlice returns the value associated with the key as a slice of strings.
func (*Configuration) GetString ¶
func (c *Configuration) GetString(key string) string
GetString returns the value associated with the key as a string.
func (*Configuration) GetStringMap ¶
func (c *Configuration) GetStringMap(key string) map[string]interface{}
GetStringMap returns the value associated with the key as a map of interfaces.
func (*Configuration) GetStringMapString ¶
func (c *Configuration) GetStringMapString(key string) map[string]string
GetStringMapString returns the value associated with the key as a map of strings.
func (*Configuration) GetStringMapStringSlice ¶
func (c *Configuration) GetStringMapStringSlice(key string) map[string][]string
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
func (*Configuration) GetStringSlice ¶
func (c *Configuration) GetStringSlice(key string) []string
GetStringSlice returns the value associated with the key as a slice of strings.
func (*Configuration) GetTime ¶
func (c *Configuration) GetTime(key string) time.Time
GetTime returns the value associated with the key as time.
func (*Configuration) Load ¶
func (c *Configuration) Load(content []byte, unmarshal Unmarshaller) error
Load ...
func (*Configuration) LoadEnvironments ¶
func (c *Configuration) LoadEnvironments(prefix string)
LoadEnvironments reads os environments with prefix such as APP_ PREFIX_FIELD1_FIELD2 will be translated into prefix.field1.field2
func (*Configuration) LoadFromDataSource ¶
func (c *Configuration) LoadFromDataSource(ds DataSource, unmarshaller Unmarshaller) error
LoadFromDataSource ...
func (*Configuration) LoadFromReader ¶
func (c *Configuration) LoadFromReader(reader io.Reader, unmarshaller Unmarshaller) error
Load loads configuration from provided data source.
func (*Configuration) OnChange ¶
func (c *Configuration) OnChange(fn func(*Configuration))
OnChange 注册change回调函数
func (*Configuration) OnLoaded ¶
func (c *Configuration) OnLoaded(fn func(*Configuration))
func (*Configuration) SetKeyDelim ¶
func (c *Configuration) SetKeyDelim(delim string)
SetKeyDelim set keyDelim of a defaultConfiguration instance.
func (*Configuration) Sub ¶
func (c *Configuration) Sub(key string) *Configuration
Sub returns new Configuration instance representing a sub tree of this instance.
func (*Configuration) UnmarshalKey ¶
func (c *Configuration) UnmarshalKey(key string, rawVal interface{}, opts ...GetOption) error
UnmarshalKey takes a single key and unmarshal it into a Struct.
func (*Configuration) UnmarshalWithExpect ¶
func (c *Configuration) UnmarshalWithExpect(key string, expect interface{}) interface{}
UnmarshalWithExpect unmarshal key, returns expect if failed
type DataSource ¶
type DataSource interface { ReadConfig() ([]byte, error) IsConfigChanged() <-chan struct{} io.Closer }
DataSource ...
type DataSourceCreatorFunc ¶
type DataSourceCreatorFunc func() DataSource
DataSourceCreatorFunc represents a dataSource creator function
type GetOption ¶
type GetOption func(o *GetOptions)
GetOption ...
func BuildinModule ¶
func TagNameJSON ¶
func TagNameJSON() GetOption
func TagNameTOML ¶
func TagNameTOML() GetOption
func TagNameYAML ¶
func TagNameYAML() GetOption
type GetOptions ¶
GetOption ...