-
-
Save amelhusic/56fca85dce24a1fdc48d0a329295c058 to your computer and use it in GitHub Desktop.
string to io.ReadCloser
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
| 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