diff --git a/cmd/neofs-node/config/calls.go b/cmd/neofs-node/config/calls.go index 1541557e07..56ffd4371d 100644 --- a/cmd/neofs-node/config/calls.go +++ b/cmd/neofs-node/config/calls.go @@ -1,14 +1,17 @@ package config import ( - "github.com/spf13/viper" + "strings" ) -// Sub returns sub-section of the Config by name. +// Sub returns subsection of the Config by name. +// +// Returns nil if subsection if missing. func (x *Config) Sub(name string) *Config { - return (*Config)( - (*viper.Viper)(x).Sub(name), - ) + return &Config{ + v: x.v, + path: append(x.path, name), + } } // Value returns configuration value by name. @@ -20,9 +23,5 @@ func (x *Config) Sub(name string) *Config { // // Returns nil if config is nil. func (x *Config) Value(name string) interface{} { - if x != nil { - return (*viper.Viper)(x).Get(name) - } - - return nil + return x.v.Get(strings.Join(append(x.path, name), separator)) } diff --git a/cmd/neofs-node/config/calls_test.go b/cmd/neofs-node/config/calls_test.go index 61d91250a3..e6da971b07 100644 --- a/cmd/neofs-node/config/calls_test.go +++ b/cmd/neofs-node/config/calls_test.go @@ -21,9 +21,6 @@ func TestConfigCommon(t *testing.T) { const nonExistentSub = "non-existent sub-section" - sub = c.Sub(nonExistentSub) - require.Nil(t, sub) - val = c.Sub(nonExistentSub).Value("value") require.Nil(t, val) }) diff --git a/cmd/neofs-node/config/config.go b/cmd/neofs-node/config/config.go index 2a560fd128..d3b06d30dd 100644 --- a/cmd/neofs-node/config/config.go +++ b/cmd/neofs-node/config/config.go @@ -13,7 +13,11 @@ import ( // Sub-trees are named configuration sub-sections, // leaves are named configuration values. // Names are of string type. -type Config viper.Viper +type Config struct { + v *viper.Viper + + path []string +} const ( separator = "." @@ -49,5 +53,7 @@ func New(_ Prm, opts ...Option) *Config { } } - return (*Config)(v) + return &Config{ + v: v, + } }