MCPcopy
hub / github.com/spf13/viper / Sub

Method Sub

viper.go:769–787  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

767func Sub(key string) *Viper { return v.Sub(key) }
768
769func (v *Viper) Sub(key string) *Viper {
770 subv := New()
771 data := v.Get(key)
772 if data == nil {
773 return nil
774 }
775
776 if reflect.TypeOf(data).Kind() == reflect.Map {
777 subv.parents = append([]string(nil), v.parents...)
778 subv.parents = append(subv.parents, strings.ToLower(key))
779 subv.automaticEnvApplied = v.automaticEnvApplied
780 subv.envPrefix = v.envPrefix
781 subv.envKeyReplacer = v.envKeyReplacer
782 subv.keyDelim = v.keyDelim
783 subv.config = cast.ToStringMap(data)
784 return subv
785 }
786 return nil
787}
788
789// GetString returns the value associated with the key as a string.
790func GetString(key string) string { return v.GetString(key) }

Callers 4

TestEnvSubConfigFunction · 0.80
TestSubFunction · 0.80
TestSubWithKeyDelimiterFunction · 0.80
SubFunction · 0.80

Calls 2

GetMethod · 0.95
NewFunction · 0.85

Tested by 3

TestEnvSubConfigFunction · 0.64
TestSubFunction · 0.64
TestSubWithKeyDelimiterFunction · 0.64