(path string)
| 329 | } |
| 330 | |
| 331 | func NewFileReader(path string) (*FileReader, error) { |
| 332 | file, err := os.Open(path) |
| 333 | if err != nil { |
| 334 | return nil, err |
| 335 | } |
| 336 | reader := FileReader{ |
| 337 | LineChan: make(chan string), |
| 338 | CloseSignal: make(chan struct{}), |
| 339 | } |
| 340 | go func() { |
| 341 | defer file.Close() |
| 342 | scanner := bufio.NewScanner(file) |
| 343 | for scanner.Scan() { |
| 344 | line := strings.TrimSpace(scanner.Text()) |
| 345 | if len(line) == 0 { |
| 346 | continue |
| 347 | } |
| 348 | lr := []rune(line) |
| 349 | if lr[0] == '#' || (len(lr) > 1 && lr[0] == '/' && lr[1] == '/') { |
| 350 | continue |
| 351 | } |
| 352 | for i, r := range lr { |
| 353 | if r == '#' || (r == '/' && i < len(lr)-1 && lr[i+1] == '/') { |
| 354 | line = strings.TrimSpace(string(lr[:i])) |
| 355 | break |
| 356 | } |
| 357 | } |
| 358 | reader.LineChan <- line |
| 359 | } |
| 360 | reader.CloseSignal <- struct{}{} |
| 361 | }() |
| 362 | return &reader, nil |
| 363 | } |
| 364 | |
| 365 | func (r *FileReader) Close() { |
| 366 | close(r.LineChan) |
no test coverage detected