MCPcopy Create free account
hub / github.com/Go-Learning-Land/Go-Learning-Archive / readFile

Function readFile

GolangBooks/masteringGo/ch04/errorInt.go:33–57  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

31}
32
33func readFile(file string) error {
34 var err error
35 fd, err := os.Open(file)
36 if err != nil {
37 return err
38 }
39 defer fd.Close()
40
41 reader := bufio.NewReader(fd)
42 n := 0
43 for {
44 line, err := reader.ReadString('\n')
45 n += len(line)
46 if err == io.EOF {
47 // End of File: nothing more to read
48 if n == 0 {
49 return emptyFile{true, n}
50 }
51 break
52 } else if err != nil {
53 return err
54 }
55 }
56 return nil
57}
58
59func main() {
60 flag.Parse()

Callers 1

mainFunction · 0.85

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected