Documentation ¶
Index ¶
- type Config
- type ViperJacket
- func (vc *ViperJacket) Close() error
- func (vc *ViperJacket) GetBool(key string, defaultVal bool) bool
- func (vc *ViperJacket) GetDuration(key string, defaultVal time.Duration) time.Duration
- func (vc *ViperJacket) GetFloat64(key string, defaultVal float64) float64
- func (vc *ViperJacket) GetInt(key string, defaultVal int) int
- func (vc *ViperJacket) GetInt32(key string, defaultVal int32) int32
- func (vc *ViperJacket) GetInt64(key string, defaultVal int64) int64
- func (vc *ViperJacket) GetIntSlice(key string, defaultVal []int) []int
- func (vc *ViperJacket) GetString(key string, defaultVal string) string
- func (vc *ViperJacket) GetStringMap(key string, defaultVal map[string]interface{}) map[string]interface{}
- func (vc *ViperJacket) GetStringMapSlice(key string, defaultVal map[string][]string) map[string][]string
- func (vc *ViperJacket) GetStringMapString(key string, defaultVal map[string]string) map[string]string
- func (vc *ViperJacket) GetStringSlice(key string, defaultVal []string) []string
- func (vc *ViperJacket) GetTime(key string, defaultVal time.Time) time.Time
- func (vc *ViperJacket) GetUint(key string, defaultVal uint) uint
- func (vc *ViperJacket) GetUint32(key string, defaultVal uint32) uint32
- func (vc *ViperJacket) GetUint64(key string, defaultVal uint64) uint64
- func (vc *ViperJacket) Load() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config interface { // Load reads and sets config. Load() error // GetBool gets boolean value of the key if present, Otherwise, it gets defaultVal. GetBool(key string, defaultVal bool) bool // GetBool gets string value of the key if present, Otherwise, it gets defaultVal. GetString(key string, defaultVal string) string // GetBool gets int value of the key if present, Otherwise, it gets defaultVal. GetInt(key string, defaultVal int) int // GetBool gets int32 value of the key if present, Otherwise, it gets defaultVal. GetInt32(key string, defaultVal int32) int32 // GetBool gets int64 value of the key if present, Otherwise, it gets defaultVal. GetInt64(key string, defaultVal int64) int64 // GetBool gets uint value of the key if present, Otherwise, it gets defaultVal. GetUint(key string, defaultVal uint) uint // GetBool gets uint32 value of the key if present, Otherwise, it gets defaultVal. GetUint32(key string, defaultVal uint32) uint32 // GetBool gets uint64 value of the key if present, Otherwise, it gets defaultVal. GetUint64(key string, defaultVal uint64) uint64 // GetBool gets float64 value of the key if present, Otherwise, it gets defaultVal. GetFloat64(key string, defaultVal float64) float64 // GetBool gets time.Time value of the key if present, Otherwise, it gets defaultVal. GetTime(key string, defaultVal time.Time) time.Time // GetBool gets time.Duration value of the key if present, Otherwise, it gets defaultVal. GetDuration(key string, defaultVal time.Duration) time.Duration // GetBool gets []int value of the key if present, Otherwise, it gets defaultVal. GetIntSlice(key string, defaultVal []int) []int // GetBool gets []string value of the key if present, Otherwise, it gets defaultVal. GetStringSlice(key string, defaultVal []string) []string // GetBool gets map[string]interface{} value of the key if present, Otherwise, it gets defaultVal. GetStringMap(key string, defaultVal map[string]interface{}) map[string]interface{} // GetBool gets map[string]string value of the key if present, Otherwise, it gets defaultVal. GetStringMapString(key string, defaultVal map[string]string) map[string]string // GetBool gets map[string][]string value of the key if present, Otherwise, it gets defaultVal. GetStringMapSlice(key string, defaultVal map[string][]string) map[string][]string // Close closes config. Close() error }
func GetOrCreate ¶
func GetOrCreate() Config
GetOrCreate returns new ViperJacket.
Implicitly, Wire-Jacket use app.conf as default config file if exists. Wire-Jacket uses envfile format if there is no file extension. You can use the --config flag to explicitly specify a config file.
The Twelve-Factors recommends use environment variables for configuration. Because it's good in container, cloud environments. However, it is not efficient to express all configs as environment variables.
So, we adopted viper, which integrates most config formats with environment variables in go. By using viper, you can use various config file formats without worrying about conversion to environment variables even if it is not in env format.
Viper v1.8.1 supports "json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env", "ini".
But viper can't integrates all complex structure with environment variables. you can check it in TestLoadDefault of viperjacket_test.go.
type ViperJacket ¶
type ViperJacket struct {
// contains filtered or unexported fields
}
func (*ViperJacket) Close ¶
func (vc *ViperJacket) Close() error
func (*ViperJacket) GetDuration ¶
func (*ViperJacket) GetFloat64 ¶
func (vc *ViperJacket) GetFloat64(key string, defaultVal float64) float64
func (*ViperJacket) GetIntSlice ¶
func (vc *ViperJacket) GetIntSlice(key string, defaultVal []int) []int
func (*ViperJacket) GetString ¶
func (vc *ViperJacket) GetString(key string, defaultVal string) string
func (*ViperJacket) GetStringMap ¶
func (vc *ViperJacket) GetStringMap(key string, defaultVal map[string]interface{}) map[string]interface{}
func (*ViperJacket) GetStringMapSlice ¶
func (*ViperJacket) GetStringMapString ¶
func (*ViperJacket) GetStringSlice ¶
func (vc *ViperJacket) GetStringSlice(key string, defaultVal []string) []string
func (*ViperJacket) GetUint32 ¶
func (vc *ViperJacket) GetUint32(key string, defaultVal uint32) uint32
func (*ViperJacket) GetUint64 ¶
func (vc *ViperJacket) GetUint64(key string, defaultVal uint64) uint64
func (*ViperJacket) Load ¶
func (vc *ViperJacket) Load() error
Load loads config file from path, if the same key exists in environment variables, Viper overwrites value of same key to environment variables. All keys are converted to lowercase and stored.