blink/internal/file/read.go

37 lines
556 B
Go
Raw Permalink Normal View History

2024-07-08 01:04:54 +00:00
package file
import (
"bufio"
"os"
"strings"
)
// Read a file
func Read(path string) ([]string, error) {
// Store lines
var lines []string
// Open file
file, err := os.Open(path)
if err != nil {
return lines, err
}
defer file.Close()
// Create scanner
scanner := bufio.NewScanner(file)
// Go through scanner
for scanner.Scan() {
// Store line
line := scanner.Text()
// Ignore empty & commented lines
if line != "" && !strings.HasPrefix(line, "#") {
2024-07-09 15:51:56 +00:00
lines = append(lines, strings.ToLower(line))
2024-07-08 01:04:54 +00:00
}
}
return lines, nil
}