1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00
lazygit/pkg/utils/io.go
Jesse Duffield 258eedb38c refactor
2021-06-02 20:33:52 +10:00

26 lines
348 B
Go

package utils
import (
"bufio"
"os"
)
func ForEachLineInFile(path string, f func(string, int)) error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
reader := bufio.NewReader(file)
for i := 0; true; i++ {
line, err := reader.ReadString('\n')
if err != nil {
break
}
f(line, i)
}
return nil
}