Skip to content

Instantly share code, notes, and snippets.

@tangnotes
Created November 29, 2016 02:30
Show Gist options
  • Save tangnotes/7467096225f86dac2138a5ee474f0aba to your computer and use it in GitHub Desktop.
Save tangnotes/7467096225f86dac2138a5ee474f0aba to your computer and use it in GitHub Desktop.
Go Reader example
//https://play.golang.org/p/d2ILCDInTy
package main
import (
"bytes"
"fmt"
"io"
)
func main() {
var body io.Reader
body = bytes.NewReader([]byte("Hello, world"))
if body == nil {
fmt.Printf("Nil\n")
} else {
fmt.Printf("Not Nil\n")
var buf = make([]byte, 1024)
n, err := body.Read(buf)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Len: %d, data: %s\n", n, string(buf))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment