Last active
November 16, 2018 22:44
-
-
Save miguelmota/0640de6d17382ac7027bcf825e39a886 to your computer and use it in GitHub Desktop.
Golang reader scanner line by line example
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
package main | |
import ( | |
"bufio" | |
"bytes" | |
"fmt" | |
) | |
func main() { | |
b := []byte("hello\nworld") | |
r := bytes.NewReader(b) | |
scanner := bufio.NewScanner(r) | |
for scanner.Scan() { | |
line := scanner.Text() | |
fmt.Printf("[log] %s\n", line) | |
} | |
} |
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
[log] hello | |
[log] world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment