config

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKey = errors.New("invalid key")

ErrInvalidKey ...

Functions

func Get

func Get(key string) interface{}

Get returns the value associated with the key

func GetBool

func GetBool(key string) bool

GetBool returns the value associated with the key as a boolean with default defaultConfig.

func GetDuration

func GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a duration with default defaultConfig.

func GetFloat64

func GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as a float64 with default defaultConfig.

func GetInt

func GetInt(key string) int

GetInt returns the value associated with the key as an integer with default defaultConfig.

func GetInt64

func GetInt64(key string) int64

GetInt64 returns the value associated with the key as an integer with default defaultConfig.

func GetSlice

func GetSlice(key string) []interface{}

GetSlice returns the value associated with the key as a slice of strings with default defaultConfig.

func GetString

func GetString(key string) string

GetString returns the value associated with the key as a string with default defaultConfig.

func GetStringMap

func GetStringMap(key string) map[string]interface{}

GetStringMap returns the value associated with the key as a map of interfaces with default defaultConfig.

func GetStringMapString

func GetStringMapString(key string) map[string]string

GetStringMapString returns the value associated with the key as a map of strings with default defaultConfig.

func GetStringMapStringSlice

func GetStringMapStringSlice(key string) map[string][]string

GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings with default defaultConfig.

func GetStringSlice

func GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a slice of strings with default defaultConfig.

func GetTime

func GetTime(key string) time.Time

GetTime returns the value associated with the key as time with default defaultConfig.

func InitConfig

func InitConfig(opts ...*Option) (err error)

New constructs a new Config with provider.

func OnChange

func OnChange(fn func(*Config))

OnChange 注册change回调函数

func SetOverride

func SetOverride(key string, val interface{}) error

func UnmarshalKey

func UnmarshalKey(key string, rawVal interface{}) error

UnmarshalKey takes a single key and unmarshal it into a Struct with default defaultdefaultConfig.

func UnmarshalWithExpect

func UnmarshalWithExpect(key string, expect interface{}) interface{}

UnmarshalWithExpect unmarshal key, returns expect if failed

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config provides Config for application.

func (*Config) Get

func (c *Config) Get(key string) interface{}

Get returns the value associated with the key

func (*Config) GetBool

func (c *Config) GetBool(key string) bool

GetBool returns the value associated with the key as a boolean.

func (*Config) GetDuration

func (c *Config) GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a duration.

func (*Config) GetFloat64

func (c *Config) GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as a float64.

func (*Config) GetInt

func (c *Config) GetInt(key string) int

GetInt returns the value associated with the key as an integer.

func (*Config) GetInt64

func (c *Config) GetInt64(key string) int64

GetInt64 returns the value associated with the key as an integer.

func (*Config) GetSlice

func (c *Config) GetSlice(key string) []interface{}

GetSlice returns the value associated with the key as a slice of strings.

func (*Config) GetSliceStringMap

func (c *Config) GetSliceStringMap(key string) []map[string]interface{}

GetSliceStringMap returns the value associated with the slice of maps.

func (*Config) GetString

func (c *Config) GetString(key string) string

GetString returns the value associated with the key as a string.

func (*Config) GetStringMap

func (c *Config) GetStringMap(key string) map[string]interface{}

GetStringMap returns the value associated with the key as a map of interfaces.

func (*Config) GetStringMapString

func (c *Config) GetStringMapString(key string) map[string]string

GetStringMapString returns the value associated with the key as a map of strings.

func (*Config) GetStringMapStringSlice

func (c *Config) GetStringMapStringSlice(key string) map[string][]string

GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a slice of strings.

func (*Config) GetTime

func (c *Config) GetTime(key string) time.Time

GetTime returns the value associated with the key as time.

func (*Config) UnmarshalKey

func (c *Config) UnmarshalKey(key string, rawVal interface{}) error

UnmarshalKey takes a single key and unmarshal it into a Struct.

func (*Config) UnmarshalWithExpect

func (c *Config) UnmarshalWithExpect(key string, expect interface{}) interface{}

UnmarshalWithExpect unmarshal key, returns expect if failed

type Option

type Option struct {
	Source source.ConfSource
}

func NewOption

func NewOption() *Option

func SetSource

func SetSource(s source.ConfSource) *Option

func (*Option) MergeOption

func (c *Option) MergeOption(opts ...*Option) *Option

func (*Option) SetSource

func (c *Option) SetSource(s source.ConfSource) *Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL