github.com/goravel/framework@v1.13.9/testing/file/file.go (about) 1 package file 2 3 import ( 4 "bufio" 5 "io" 6 "os" 7 ) 8 9 func GetLineNum(file string) int { 10 total := 0 11 f, _ := os.OpenFile(file, os.O_RDONLY, 0444) 12 buf := bufio.NewReader(f) 13 14 for { 15 _, err := buf.ReadString('\n') 16 if err != nil { 17 if err == io.EOF { 18 total++ 19 20 break 21 } 22 } else { 23 total++ 24 } 25 } 26 27 defer f.Close() 28 29 return total 30 }