1package utils
2
3import (
4	"bufio"
5	"os"
6)
7
8func ForEachLineInFile(path string, f func(string, int)) error {
9	file, err := os.Open(path)
10	if err != nil {
11		return err
12	}
13	defer file.Close()
14
15	reader := bufio.NewReader(file)
16	for i := 0; true; i++ {
17		line, err := reader.ReadString('\n')
18		if err != nil {
19			break
20		}
21		f(line, i)
22	}
23
24	return nil
25}
26