Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active November 16, 2018 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/0640de6d17382ac7027bcf825e39a886 to your computer and use it in GitHub Desktop.
Save miguelmota/0640de6d17382ac7027bcf825e39a886 to your computer and use it in GitHub Desktop.
Golang reader scanner line by line example
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)
}
}
[log] hello
[log] world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment