(lines []string)
| 30 | } |
| 31 | |
| 32 | func createConfigMap(lines []string) configMap { |
| 33 | cm := newConfigMap() |
| 34 | var sectionName string |
| 35 | const expectedParts = 2 |
| 36 | for _, line := range lines { |
| 37 | line = strings.TrimSpace(line) |
| 38 | if isSection(line) { |
| 39 | sectionName = extractSectionName(line) |
| 40 | continue |
| 41 | } |
| 42 | |
| 43 | keyValuePair := strings.SplitN(line, "=", expectedParts) |
| 44 | key := strings.TrimSpace(keyValuePair[0]) |
| 45 | |
| 46 | value := "" |
| 47 | if len(keyValuePair) == expectedParts { |
| 48 | value = strings.TrimSpace(keyValuePair[1]) |
| 49 | } |
| 50 | cm.Add(sectionName, key, value) |
| 51 | } |
| 52 | return cm |
| 53 | } |
| 54 | |
| 55 | func isSection(line string) bool { |
| 56 | return len(line) > 2 && strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") |
no test coverage detected