maraudir/common/read.go
2024-11-21 00:16:20 -06:00

24 lines
341 B
Go

package common
import (
"bufio"
"os"
"strings"
)
func Readfile(filename string, out chan<- string) error {
file, err := os.Open(filename)
if err != nil {
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
out <- line
}
return scanner.Err()
}