econf

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 12 Imported by: 98

Documentation

Index

Constants

View Source
const PackageName = "core.econf"

PackageName defines package name.

Variables

View Source
var ErrInvalidKey = errors.New("invalid key, maybe not exist in config")

ErrInvalidKey ...

Functions

func Apply

func Apply(conf map[string]interface{}) error

Apply ...

func Debug

func Debug(sep string)

Debug ...

func Get

func Get(key string) interface{}

Get returns an interface. For a specific value use one of the Get____ methods.

func GetBool

func GetBool(key string) bool

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

func GetDuration

func GetDuration(key string) time.Duration

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

func GetFloat64

func GetFloat64(key string) float64

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

func GetInt

func GetInt(key string) int

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

func GetInt64

func GetInt64(key string) int64

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

func GetOptionSquash added in v1.1.6

func GetOptionSquash() bool

GetOptionSquash returns Squash config of default container

func GetOptionTagName added in v0.7.0

func GetOptionTagName() string

GetOptionTagName returns optionTag config of default container

func GetOptionWeaklyTypedInput added in v0.7.0

func GetOptionWeaklyTypedInput() bool

GetOptionWeaklyTypedInput returns WeaklyTypedInput config of default container

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

func GetString(key string) string

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

func GetStringMap

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

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

func GetStringMapString

func GetStringMapString(key string) map[string]string

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

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 defaultConfiguration.

func GetStringSlice

func GetStringSlice(key string) []string

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

func GetTime

func GetTime(key string) time.Time

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

func LoadFromDataSource

func LoadFromDataSource(ds DataSource, unmarshaller Unmarshaller, opts ...Option) error

LoadFromDataSource load configuration from data source if data source supports dynamic config, a monitor goroutine would be

func LoadFromReader

func LoadFromReader(r io.Reader, unmarshaller Unmarshaller) error

LoadFromReader loads configuration from provided provider with default defaultConfiguration.

func OnChange

func OnChange(fn func(*Configuration))

OnChange 注册change回调函数

func RawConfig

func RawConfig() []byte

RawConfig 原始配置

func Reset

func Reset()

Reset resets all to default settings.

func Set

func Set(key string, val interface{})

Set sets config value for key

func Traverse

func Traverse(sep string) map[string]interface{}

Traverse ...

func UnmarshalKey

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

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 ConfigType added in v0.4.5

type ConfigType string

ConfigType 配置类型

var (
	// ConfigTypeJSON ...
	ConfigTypeJSON ConfigType = "json"
	// ConfigTypeToml ...
	ConfigTypeToml ConfigType = "toml"
	// ConfigTypeYaml ...
	ConfigTypeYaml ConfigType = "yaml"
)

type Configuration

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

Configuration ...

func New

func New() *Configuration

New constructs a new Configuration with provider.

func Sub added in v1.0.0

func Sub(key string) *Configuration

Sub return sub-configuration of defaultConfiguration

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) GetSlice

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

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

func (*Configuration) GetSliceStringMap

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

GetSliceStringMap returns the value associated with the slice of maps.

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) LoadFromDataSource

func (c *Configuration) LoadFromDataSource(ds DataSource, unmarshaller Unmarshaller, opts ...Option) error

LoadFromDataSource ...

func (*Configuration) LoadFromReader

func (c *Configuration) LoadFromReader(reader io.Reader, unmarshaller Unmarshaller) error

LoadFromReader loads configuration from provided data source.

func (*Configuration) OnChange

func (c *Configuration) OnChange(fn func(*Configuration))

OnChange register a callback when configuration change emit.

func (*Configuration) Set

func (c *Configuration) Set(key string, val interface{}) error

Set ...

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 subtree of this instance.

func (*Configuration) UnmarshalKey

func (c *Configuration) UnmarshalKey(key string, rawVal interface{}, opts ...Option) 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

func (*Configuration) WriteConfig

func (c *Configuration) WriteConfig() error

WriteConfig ...

type Container added in v0.4.0

type Container struct {
	TagName          string
	WeaklyTypedInput bool
	Squash           bool
}

Container defines a component instance.

type DataSource

type DataSource interface {
	Parse(addr string, watch bool) ConfigType
	ReadConfig() ([]byte, error)
	IsConfigChanged() <-chan struct{}
	io.Closer
}

DataSource ...

type Option added in v0.4.0

type Option func(o *Container)

Option is an optional argument to Container.

func WithSquash added in v1.1.6

func WithSquash(squash bool) Option

WithSquash sets if allow squash tags in embedded struct

func WithTagName added in v0.4.0

func WithTagName(tag ConfigType) Option

WithTagName sets tagName when unmarshal raw config to struct.

func WithWeaklyTypedInput added in v0.4.3

func WithWeaklyTypedInput(weaklyTypedInput bool) Option

WithWeaklyTypedInput sets if allow weaklyTypedInput.

type Unmarshaller

type Unmarshaller = func([]byte, interface{}) error

Unmarshaller ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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