有效地使用文档来查找所有以io.Reader作为参数的标准库函数。

huangapple go评论93阅读模式
英文:

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) {
  1. https://cs.opensource.google/go
英文:

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) {
  1. https://cs.opensource.google/go

huangapple
  • 本文由 发表于 2021年6月17日 17:59:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/68017073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定