viperjacket

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: Apache-2.0 Imports: 8 Imported by: 6

README

viper-jacket

Jacket of spf13/viper: config for wire-jacket.

Documentation

Index

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

func (vc *ViperJacket) GetBool(key string, defaultVal bool) bool

func (*ViperJacket) GetDuration

func (vc *ViperJacket) GetDuration(key string, defaultVal time.Duration) time.Duration

func (*ViperJacket) GetFloat64

func (vc *ViperJacket) GetFloat64(key string, defaultVal float64) float64

func (*ViperJacket) GetInt

func (vc *ViperJacket) GetInt(key string, defaultVal int) int

func (*ViperJacket) GetInt32

func (vc *ViperJacket) GetInt32(key string, defaultVal int32) int32

func (*ViperJacket) GetInt64

func (vc *ViperJacket) GetInt64(key string, defaultVal int64) int64

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 (vc *ViperJacket) GetStringMapSlice(key string, defaultVal map[string][]string) map[string][]string

func (*ViperJacket) GetStringMapString

func (vc *ViperJacket) GetStringMapString(key string, defaultVal map[string]string) map[string]string

func (*ViperJacket) GetStringSlice

func (vc *ViperJacket) GetStringSlice(key string, defaultVal []string) []string

func (*ViperJacket) GetTime

func (vc *ViperJacket) GetTime(key string, defaultVal time.Time) time.Time

func (*ViperJacket) GetUint

func (vc *ViperJacket) GetUint(key string, defaultVal uint) uint

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.

Jump to

Keyboard shortcuts

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