| 767 | func Sub(key string) *Viper { return v.Sub(key) } |
| 768 | |
| 769 | func (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. |
| 790 | func GetString(key string) string { return v.GetString(key) } |