I need to read specific line of file. Some of related topics I've read: golang: How do I determine the number of lines in a file efficiently?, https://stackoverflow.com/questions/30692567/what-is-the-best-way-to-count-lines-in-file
I've write the following function and it works as expected, but I have doubt: may be there is better (efficient) way?
func ReadLine(r io.Reader, lineNum int) (line string, lastLine int, err error) {
sc := bufio.NewScanner(r)
for sc.Scan() {
lastLine++
if lastLine == lineNum {
return sc.Text(), lastLine, sc.Err()
}
}
return line, lastLine, io.EOF
}