有关“所有已知实现"的文档;接口数量 [英] Documentation On "All Known Implementation" of Interfaces
问题描述
学习Go的几个月时间里,我发现 os.File
实现了通过实现 io.Reader
接口.org/pkg/os/#File.Read> Read(b [] byte)(n int,err错误)
函数.这使我可以使用缓冲读取器通过类似以下操作来读取文件:
Few months into learning Go, I just discover that os.File
implements the io.Reader
interface by implementing the Read(b []byte) (n int, err error)
function. This allows me to use a buffered reader to read a file by do something like:
f, err := os.Open("myfile.txt")
bufReader := bufio.NewReader(f)
除非我想念它,否则看起来像Java接口文档中的接口一样,接口的Go文档中没有所有已知的实现类".
Unless I miss it, it looks like there isn't an "All Known Implementing Classes" in Go documents on interfaces, like those found in Java interfaces documentation.
是否有任何方法可以识别在Go中实现接口的类型?
Are there any ways to identify the types that implement an interface in Go?
推荐答案
您可以使用godoc命令的静态分析工具找到所需的信息以及更多信息.在命令行中运行以下命令: godoc -http =:8080" -analysis ="type"
.使用文档,您可以找到哪些类型实现了接口以及为该类型设置的方法.
You can find the info you want and more using the godoc command's static analysis tools. Run the following at the command line: godoc -http=":8080" -analysis="type"
. Using the documentation you can find out what types implement an interface and the method set for a type.
还有一个指针分析,可让您查找各种类型的呼叫者和被呼叫者.频道发送--->接收分析非常简洁.
There is also a pointer analysis that allows you to find callers and callees of various types. The channel send<--->receive analysis is pretty neat.
您还可以在 http://golang.org/上阅读有关godoc工具完成的静态分析的更多信息.lib/godoc/analysis/help.html
这篇关于有关“所有已知实现"的文档;接口数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!