Created
April 10, 2021 18:44
-
-
Save OffXec/2123b8c1c3ca53e3242b0df153694b57 to your computer and use it in GitHub Desktop.
GoLang doodles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func readFileWithReadString(fn string) (err error) { | |
fmt.Println("readFileWithReadString") | |
file, err := os.Open(fn) | |
if err != nil { | |
return err | |
} | |
defer file.Close() | |
// Start reading from the file with a reader. | |
reader := bufio.NewReader(file) | |
var line string | |
for { | |
line, err = reader.ReadString('\n') | |
if err != nil && err != io.EOF { | |
break | |
} | |
// Process the line here. | |
fmt.Printf(" > Read %d characters\n", len(line)) | |
fmt.Printf(" > > %s\n", limitLength(line, 50)) | |
if err != nil { | |
break | |
} | |
} | |
if err != io.EOF { | |
fmt.Printf(" > Failed with error: %v\n", err) | |
return err | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment