io.ReadCloser

 

 

package main

import (
    "bytes"
//  "strings"
    "fmt"
    "io/ioutil"
)
func main() {
    r := ioutil.NopCloser(bytes.NewReader([]byte("hello world"))) // r type is io.ReadCloser
    //r := ioutil.NopCloser(strings.NewReader("hello world"))

    // example to test r
    buf := new(bytes.Buffer)
    buf.ReadFrom(r)
    r.Close()
    s := buf.String()
    fmt.Println(s)
}

 

posted @ 2021-02-23 14:49  牧 天  阅读(856)  评论(0)    收藏  举报