Created
November 29, 2016 02:30
-
-
Save tangnotes/7467096225f86dac2138a5ee474f0aba to your computer and use it in GitHub Desktop.
Go Reader example
This file contains hidden or 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
//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