2021-05-21 11:50:40 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2021-05-21 17:28:06 +00:00
|
|
|
"strings"
|
2021-05-21 11:50:40 +00:00
|
|
|
)
|
|
|
|
|
2021-05-21 17:28:06 +00:00
|
|
|
// Sub returns subsection of the Config by name.
|
|
|
|
//
|
|
|
|
// Returns nil if subsection if missing.
|
2021-05-21 11:50:40 +00:00
|
|
|
func (x *Config) Sub(name string) *Config {
|
2021-05-21 17:28:06 +00:00
|
|
|
return &Config{
|
|
|
|
v: x.v,
|
|
|
|
path: append(x.path, name),
|
|
|
|
}
|
2021-05-21 11:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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{} {
|
2021-05-21 17:28:06 +00:00
|
|
|
return x.v.Get(strings.Join(append(x.path, name), separator))
|
2021-05-21 11:50:40 +00:00
|
|
|
}
|