doujiang1001
2018-08-29 11:49
浏览 1.4k
已采纳

如何将io.Reader转换为io.ReadCloser? [重复]

This question already has an answer here:

I have an io.Reader that doesn't require closing:

stringReader := strings.NewReader("shiny!")

And I want to pass it to a method that receives an io.ReadCloser

func readAndClose(source io.ReadCloser) {
    ...
}

How do I turn the io.Reader into a io.ReadCloser without specially creating a struct that implements the Close method?

</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 在这里有答案:</ p>

  • Golang io / ioutil NopCloser 2个答案 </ span> </ li> </ ul> </ div>

    我有一个 io.Reader </ code>不需要关闭:</ p> \ n

      stringReader:= strings.NewReader(“ shiny!”)
     </ code> </ pre> 
     
     

    我想将其传递给接收<code的方法 > io.ReadCloser </ code> </ p>

      func readAndClose(源io.ReadCloser){
     ... 
    } 
     </ code> </ pre> \  n 
     

    如何将 io.Reader </ code>转换为 io.ReadCloser </ code>,而无需专门创建实现 Close </ code>方法的结构 ?</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题