(fileName string, depth int)
| 66 | } |
| 67 | |
| 68 | func (parser *parser) readConfigFile(fileName string, depth int) ([]string, error) { |
| 69 | if depth >= configMaxRecursion { |
| 70 | return nil, fmt.Errorf("reached maximum Include depth of %d", depth) |
| 71 | } |
| 72 | readFile, err := os.Open(fileName) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | defer readFile.Close() |
| 77 | |
| 78 | fileScanner := bufio.NewScanner(readFile) |
| 79 | var fileLines []string |
| 80 | for fileScanner.Scan() { |
| 81 | line := strings.TrimSpace(fileScanner.Text()) |
| 82 | if isCommentOrEmpty(line) { |
| 83 | continue |
| 84 | } |
| 85 | if isIncludeLine(line) { |
| 86 | includeLines, err := parser.processIncludeLine(line, depth+1) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | fileLines = append(fileLines, includeLines...) |
| 91 | } else { |
| 92 | fileLines = append(fileLines, line) |
| 93 | } |
| 94 | } |
| 95 | if err := fileScanner.Err(); err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | return fileLines, nil |
| 99 | } |
| 100 | |
| 101 | func (parser *parser) processIncludeLine(line string, depth int) ([]string, error) { |
| 102 | const expectedParts = 2 |
no test coverage detected