This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
func LinesInFile(fileName string) ([]string, error) {
|
||||
f, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
// Create new Scanner.
|
||||
scanner := bufio.NewScanner(f)
|
||||
result := []string{}
|
||||
// Use Scan.
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
// Append line to result.
|
||||
result = append(result, line)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user