问题描述
几个月后,我发现通过实施界面功能。这允许我使用缓冲读取器通过执行以下操作来读取文件: f,err:= os.Open( myfile.txt)
bufReader:= bufio.NewReader(f)
除非我错过了它,看起来在接口上的Go文档中没有所有已知的实现类,就像在Java接口文档中找到的那样。
有没有什么方法在Go中识别实现接口的类型?
您可以使用godoc命令的static分析工具。在命令行运行以下命令: godoc -http =:8080-analysis =type
。使用文档可以找出实现接口的类型和为类型设置的方法。
还有一个指针分析,可以让你找到各种类型的调用者和被调用者。频道发送< --->接收分析非常整齐。
您还可以阅读更多关于godoc工具在
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)
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.
Are there any ways to identify the types that implement an interface in Go?
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.
You can also read more about the static analysis done by the godoc tool at http://golang.org/lib/godoc/analysis/help.html
这篇关于Golang - 关于“所有已知实现”的文档接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!