config

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllSettings

func AllSettings() map[string]interface{}

AllSettings gets all settings in config.

func Get

func Get(key string, defaultValue ...interface{}) interface{}

Get is shorthand for GetValue.

func GetBool

func GetBool(key string, defaultValue ...bool) bool

GetBool gets bool value of the key or fallback to the default value.

func GetDuration

func GetDuration(key string, defaultValue ...time.Duration) time.Duration

GetDuration gets duration value of the key or fallback to the default value.

func GetFloat64

func GetFloat64(key string, defaultValue ...float64) float64

GetFloat64 gets float64 value of the key or fallback to the default value.

func GetInt

func GetInt(key string, defaultValue ...int) int

GetInt gets int value of the key or fallback to the default value.

func GetInt64

func GetInt64(key string, defaultValue ...int64) int64

GetInt64 gets int64 value of the key or fallback to the default value.

func GetString

func GetString(key string, defaultValue ...string) string

GetString gets string value of the key or fallback to the default value.

func GetStringMap

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

GetStringMap gets map[string]interface{} value of the key or fallback to the default value.

func GetStringMapString

func GetStringMapString(key string, defaultValue ...map[string]string) map[string]string

GetStringMapString gets map[string]string value of the key or fallback to the default value.

func GetStringSlice

func GetStringSlice(key string, defaultValue ...[]string) []string

GetStringSlice gets string slice value of the key or fallback to the default value.

func GetTime

func GetTime(key string, defaultValue ...time.Time) time.Time

GetTime gets time value of the key or fallback to the default value.

func GetValue

func GetValue(key string, defaultValue ...interface{}) interface{}

GetValue gets value of the key or fallback to the default value.

func Has

func Has(key string) bool

Has checks to see if the key has been set in any of the data locations. Has is case-insensitive for a key.

func Load

func Load(configPath string, configName ...string)

Load config into global environment. Default config name is "config".

func LoadAll

func LoadAll(configPath string) error

LoadAll loads all config contents in the dir path

func LoadEnv

func LoadEnv(prefix ...string)

LoadEnv loads env from .env or command line Use prefix to avoid conflicts with other env variables Same config key in env will override that in config file

func MergeConfigMap

func MergeConfigMap(cfg map[string]interface{})

MergeConfigMap merges the configuration from the map given with an existing config. Note that the map given may be modified.

func Set

func Set(key string, value interface{})

Set sets the value for the key in the override register. Set is case-insensitive for a key. Will be used instead of values obtained via flags, config file, ENV, default, or key/value store.

func Unmarshal

func Unmarshal(rawVal interface{}) error

Unmarshal unmarshals the config into a Struct. Make sure that the tags on the fields of the structure are properly set.

func UnmarshalKey

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

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

Types

type Config

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

Config is based on spf13/viper and extends by supporting default value

func New

func New() *Config

New returns a new Config instance

func Sub

func Sub(key string) *Config

Sub returns a new Config instance representing a sub tree of this instance. Sub is case-insensitive for a key.

func (*Config) AllSettings

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

func (*Config) Get

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

func (*Config) GetBool

func (c *Config) GetBool(key string, defaultValue ...bool) bool

func (*Config) GetDuration

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

func (*Config) GetFloat64

func (c *Config) GetFloat64(key string, defaultValue ...float64) float64

func (*Config) GetInt

func (c *Config) GetInt(key string, defaultValue ...int) int

func (*Config) GetInt64

func (c *Config) GetInt64(key string, defaultValue ...int64) int64

func (*Config) GetString

func (c *Config) GetString(key string, defaultValue ...string) string

func (*Config) GetStringMap

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

func (*Config) GetStringMapString

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

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(key string, defaultValue ...[]string) []string

func (*Config) GetTime

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

func (*Config) GetValue

func (c *Config) GetValue(key string, defaultValue ...interface{}) interface{}

func (*Config) Has

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

func (*Config) LoadEnv

func (c *Config) LoadEnv(prefix ...string)

func (*Config) MergeConfigMap

func (c *Config) MergeConfigMap(cfg map[string]interface{})

func (*Config) Set

func (c *Config) Set(key string, value interface{})

func (*Config) Sub

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

func (*Config) Unmarshal

func (c *Config) Unmarshal(rawVal interface{}) error

func (*Config) UnmarshalKey

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

Jump to

Keyboard shortcuts

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