maraudir/common/read.go

24 lines
341 B
Go
Raw Normal View History

2024-11-21 06:16:20 +00:00
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()
}