英文:
Effectively using the docs to find all standard library functions that take an io.Reader as an argument
问题
我有一个关于如何在Go文档中查找信息的问题。
我看到net/http Response.Body 是一个 io.ReadCloser 的值。
go doc io readcloser
导致了 go doc io reader
,但是那是个死胡同。最终我通过一些 duck.go 搜索学会了可以用 ioutil.ReadAll(rs.Body) 来读取它。我应该如何通过 Go文档 找到这个答案呢?
我猜我的问题可能是:我如何找到所有在所有包中接受一个参数 (r io.Reader) 的函数,就像 func ReadAll(r io.Reader) ([]byte, error) 这样的函数一样?
英文:
I have a question about how to find information in the Go docs.
I saw that net/http Response.Body is a value of io.ReadCloser.
go doc io readcloser
lead to go doc io reader
, but that was a deadend. I eventually learned I could read it with ioutil.ReadAll(rs.Body) through some duck.go searches. How would I have figured that out through the go docs?
I guess my question might be: How could I find all functions in all packages that take an argument (r io.Reader)... like func ReadAll(r io.Reader) ([]byte, error) does?
答案1
得分: 1
这个网站[1]支持正则表达式,所以你可以这样做:
case:y func\s[A-Z].+io.Reader[,)]
结果非常多,因为io.Reader
可以说是最常见的接口值。以下是一些结果:
src/encoding/csv/reader.go
func NewReader(r io.Reader) *Reader {
src/testing/iotest/reader.go
func HalfReader(r io.Reader) io.Reader { return &halfReader{r} }
func OneByteReader(r io.Reader) io.Reader { return &oneByteReader{r} }
src/image/gif/reader.go
func Decode(r io.Reader) (image.Image, error) {
func DecodeAll(r io.Reader) (*GIF, error) {
func DecodeConfig(r io.Reader) (image.Config, error) {
英文:
This site [1] supports Regular Expressions, so you can do this:
case:y func\s[A-Z].+io.Reader[,)]
It's quite a lot of results, as io.Reader
is arguably the most common interface value. Here are some results:
src/encoding/csv/reader.go
func NewReader(r io.Reader) *Reader {
src/testing/iotest/reader.go
func HalfReader(r io.Reader) io.Reader { return &halfReader{r} }
func OneByteReader(r io.Reader) io.Reader { return &oneByteReader{r} }
src/image/gif/reader.go
func Decode(r io.Reader) (image.Image, error) {
func DecodeAll(r io.Reader) (*GIF, error) {
func DecodeConfig(r io.Reader) (image.Config, error) {
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论