fix panic while saving ini file

This commit is contained in:
Carlos Henrique Guardao Gandarez 2020-05-26 09:05:55 -03:00
parent 13df721090
commit 074ed18f7e
No known key found for this signature in database
GPG key ID: 18F887F1A52ABDE5

View file

@ -1644,9 +1644,12 @@ func (v *Viper) marshalWriter(f afero.File, configType string) error {
for i := 0; i < len(keys); i++ { for i := 0; i < len(keys); i++ {
key := keys[i] key := keys[i]
lastSep := strings.LastIndex(key, ".") lastSep := strings.LastIndex(key, ".")
sectionName := key[:(lastSep)] sectionName := ""
if lastSep > 0 {
sectionName = key[:(lastSep)]
}
keyName := key[(lastSep + 1):] keyName := key[(lastSep + 1):]
if sectionName == "default" { if sectionName == ini.DefaultSection {
sectionName = "" sectionName = ""
} }
cfg.Section(sectionName).Key(keyName).SetValue(v.Get(key).(string)) cfg.Section(sectionName).Key(keyName).SetValue(v.Get(key).(string))