27 lines
429 B
Go
27 lines
429 B
Go
// Package file provides useful methods for interacting with files
|
|
package file
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
)
|
|
|
|
func ReadLines(filePath string) []string {
|
|
lines := []string{}
|
|
|
|
file, openErr := os.Open(filePath)
|
|
|
|
if openErr != nil {
|
|
return lines
|
|
}
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for hasLine := scanner.Scan(); hasLine; hasLine = scanner.Scan() {
|
|
line := scanner.Text()
|
|
lines = append(lines, line)
|
|
}
|
|
|
|
return lines
|
|
}
|