Skip to content

Commit

Permalink
INI parser, set section to 'default' when key/value pair is outside a…
Browse files Browse the repository at this point in the history
… section
  • Loading branch information
Ariel Abuel committed Jul 18, 2023
1 parent fd53ee0 commit d65bd23
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion config/data_source_common_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,20 @@ func iniParser(datastream interface{}) map[string]map[string]interface{} {

scanner := bufio.NewScanner(strings.NewReader(datastream.(string)))
ini := make(map[string]map[string]interface{})
var section string
section := ""
for scanner.Scan() {
line := scanner.Text()
if sect.MatchString(line) {
section = sect.FindStringSubmatch(line)[1]
ini[section] = make(map[string]interface{})
} else if data.MatchString(line) {
kv := data.FindStringSubmatch(line)
if section == "" {
section = "default"
ini[section] = make(map[string]interface{})
}
ini[section][strings.TrimSpace(kv[1])] = strings.TrimSpace(kv[2])

}
}
return ini
Expand Down

0 comments on commit d65bd23

Please sign in to comment.