Skip to content

Instantly share code, notes, and snippets.

@rfyiamcool
Created August 3, 2020 10:59
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 rfyiamcool/9e182642151316704b81737b6abd8c54 to your computer and use it in GitHub Desktop.
Save rfyiamcool/9e182642151316704b81737b6abd8c54 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"io/ioutil"
)
func main() {
r := ioutil.NopCloser(bytes.NewReader([]byte("hello world"))) // r type is io.ReadCloser
// example to test r
buf := new(bytes.Buffer)
buf.ReadFrom(r)
r.Close()
s := buf.String()
fmt.Println(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment