Documentation ¶
Index ¶
- type Configuration
- func (c *Configuration) GetBool(key string) bool
- func (c *Configuration) GetByte(key string, enc Encoding) (b []byte, err error)
- func (c *Configuration) GetDuration(key string, isISO8601 bool) time.Duration
- func (c *Configuration) GetFloat32(key string) float32
- func (c *Configuration) GetFloat64(key string) float64
- func (c *Configuration) GetInt(key string) int
- func (c *Configuration) GetInt64(key string) int64
- func (c *Configuration) GetString(key string) string
- func (c *Configuration) GetStringMap(key string, vType reflect.Type) (interface{}, error)
- func (c *Configuration) GetStringSlice(key string) []string
- func (c *Configuration) GetTime(key string) (time.Time, error)
- func (c *Configuration) GetUInt32(key string) uint32
- func (c *Configuration) GetUInt64(key string) uint64
- func (c *Configuration) GetUInt8(key string) uint8
- func (c *Configuration) Initialize() error
- func (c *Configuration) InitializeComponentConfig(compConf interface{}) error
- func (c *Configuration) IsInitialized() bool
- func (c *Configuration) SetFormat(formatType string)
- func (c *Configuration) Sub(tag string) *Configuration
- type Encoding
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
type Configuration struct { AppName string EnvironmentName string // contains filtered or unexported fields }
Configuration contains the application configuration parameters.
func NewConfiguration ¶
func NewConfiguration(appName, envname string, searchPaths []string) *Configuration
NewConfiguration returns a new configuration based on the given parameters.
func NewConfigurationFromReader ¶
func NewConfigurationFromReader(format string, in io.Reader) (*Configuration, error)
NewConfigurationFromReader creates a configuration using the content read from the given stream using the provided format. Supported formats are "json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl".
func (*Configuration) GetBool ¶
func (c *Configuration) GetBool(key string) bool
GetBool returns the values associated with the given key as a boolean.
func (*Configuration) GetByte ¶
func (c *Configuration) GetByte(key string, enc Encoding) (b []byte, err error)
GetByte returns the values associated with the given key as a byte array using the given encoding.
func (*Configuration) GetDuration ¶
func (c *Configuration) GetDuration(key string, isISO8601 bool) time.Duration
GetDuration returns the values associated with the given key as a Duration If the format of the value does not match Duration 0 is returned.
func (*Configuration) GetFloat32 ¶
func (c *Configuration) GetFloat32(key string) float32
GetFloat32 returns the values associated with the given key as a float32.
func (*Configuration) GetFloat64 ¶
func (c *Configuration) GetFloat64(key string) float64
GetFloat64 returns the values associated with the given key as a float64.
func (*Configuration) GetInt ¶
func (c *Configuration) GetInt(key string) int
GetInt returns the values associated with the given key as an integer.
func (*Configuration) GetInt64 ¶
func (c *Configuration) GetInt64(key string) int64
GetInt64 returns the values associated with the given key as a int64.
func (*Configuration) GetString ¶
func (c *Configuration) GetString(key string) string
GetString returns the values associated with the given key as a string.
func (*Configuration) GetStringMap ¶
func (c *Configuration) GetStringMap(key string, vType reflect.Type) (interface{}, error)
GetStringMap returns the values associated with the given key as a map[string]T{}.
func (*Configuration) GetStringSlice ¶
func (c *Configuration) GetStringSlice(key string) []string
GetStringSlice returns the values associated with the given key as a string slice.
func (*Configuration) GetTime ¶
func (c *Configuration) GetTime(key string) (time.Time, error)
GetTime returns the string value associated with the given key as a time.
func (*Configuration) GetUInt32 ¶
func (c *Configuration) GetUInt32(key string) uint32
GetUInt32 returns the values associated with the given key as a uint32.
func (*Configuration) GetUInt64 ¶
func (c *Configuration) GetUInt64(key string) uint64
GetUInt64 returns the values associated with the given key as a uint64.
func (*Configuration) GetUInt8 ¶
func (c *Configuration) GetUInt8(key string) uint8
GetUInt8 returns the values associated with the given key as a uint8.
func (*Configuration) Initialize ¶
func (c *Configuration) Initialize() error
Initialize initializes the configuration.
func (*Configuration) InitializeComponentConfig ¶
func (c *Configuration) InitializeComponentConfig(compConf interface{}) error
InitializeComponentConfig initializes a component configuration object. This method uses tags to read the key path where to read the value in the configuration file for a given field as well as to determine default values, and validation tags for validation (see https://godoc.org/gopkg.in/go-playground/validator.v9). Example:
type TestConfig struct { I int `configkey:"unittest.i" validate:"min=10" default:"10"` S string `configkey:"unittest.s" validate:"required" default:"hoge"` Ss []string `configkey:"unittest.ss" validate:"dive,required" default:"hoge,fuga"` B bool `configkey:"unittest.b" default:"true"` Utf8byte []byte `configkey:"unittest.utf8byte,utf8" validate:"required" default:"abcde"` Hexbytes []byte `configkey:"unittest.hexbyte,hex" validate:"required" default:"abcd0e"` Dr time.Duration `configkey:"unittest.dr,duration,iso8601" validate:"required" default:"PT1H30M"` I64 int64 `configkey:"unittest.i64" validate:"min=11" default:"132904"` m map[string]struct { nestedString string `configkey:"ex_string" default:"example"` } `configkey:"unittest.nested_map"` }
func (*Configuration) IsInitialized ¶
func (c *Configuration) IsInitialized() bool
IsInitialized returns whether the configuration is initialized.
func (*Configuration) SetFormat ¶
func (c *Configuration) SetFormat(formatType string)
SetFormat specifies the format of the configuration file. viper automatically detects the format so this method is mainly for testing.
func (*Configuration) Sub ¶
func (c *Configuration) Sub(tag string) *Configuration
Sub returns a new initialized SubConfiguration