1aa88159ca
In some cases viper doesn't interpret `section.value` as a subsection with `section` name, but value is value still can be accessed through full pathname. Fix `Config.Sub` method implementation in order to always interpret configuration like described above as a subsection. From now method never returns nil, therefore an additional check has been removed from the `Value` method. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
27 lines
599 B
Go
27 lines
599 B
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// Sub returns subsection of the Config by name.
|
|
//
|
|
// Returns nil if subsection if missing.
|
|
func (x *Config) Sub(name string) *Config {
|
|
return &Config{
|
|
v: x.v,
|
|
path: append(x.path, name),
|
|
}
|
|
}
|
|
|
|
// Value returns configuration value by name.
|
|
//
|
|
// Result can be casted to a particular type
|
|
// via corresponding function (e.g. StringSlice).
|
|
// Note: casting via Go `.()` operator is not
|
|
// recommended.
|
|
//
|
|
// Returns nil if config is nil.
|
|
func (x *Config) Value(name string) interface{} {
|
|
return x.v.Get(strings.Join(append(x.path, name), separator))
|
|
}
|