如何找出哪些类型实现Golang中的哪个接口? [英] How to find out which types implement which interface in Golang?
本文介绍了如何找出哪些类型实现Golang中的哪个接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
在包 io
中,类型 ByteReader
定义了一个包装方法 ReadByte()字节,错误错误)
。
在标准库中找出 哪些类型的最简单方法是(在golang.org/pkg 中列出)满足此界面?
这只是一个经验问题或者是否有其他帮助?
解决方案
jnml @ fsc-r630:〜/ go / src / pkg $ egrep -nr'^ func( 。*)ReadByte \('*
bufio / bufio.go:165:func(b * Reader)ReadByte()(c byte,err error){
bytes / reader.go:59: func(r * Reader)ReadByte()(b字节,err错误){
bytes / buffer.go:289:func(b * Buffer)ReadByte()(c byte,err error){
编码/ xml / xml_test.go:234:func(d * downCaser)ReadByte()(c字节,错误错误){
strings / reader.go:58:func(r * Reader)ReadByte()(b字节,err错误){
jnml @ fsc-r630:〜/ go / src / pkg $
此外,golang.org网站还具有区分大小写的搜索功能。
Example:
In package io
the type ByteReader
defines an interface that wraps the method ReadByte() (c byte, err error)
.
What is the easiest way to find out which types in the standard library (i.e. listed here in golang.org/pkg) satisfy this interface?
Is this just a matter of experience or is there any other help?
解决方案
Mostly by experience. Anyway, for example:
jnml@fsc-r630:~/go/src/pkg$ egrep -nr '^func (.*) ReadByte\(' *
bufio/bufio.go:165:func (b *Reader) ReadByte() (c byte, err error) {
bytes/reader.go:59:func (r *Reader) ReadByte() (b byte, err error) {
bytes/buffer.go:289:func (b *Buffer) ReadByte() (c byte, err error) {
encoding/xml/xml_test.go:234:func (d *downCaser) ReadByte() (c byte, err error) {
strings/reader.go:58:func (r *Reader) ReadByte() (b byte, err error) {
jnml@fsc-r630:~/go/src/pkg$
And also the golang.org site has a case sensitive search capability.
这篇关于如何找出哪些类型实现Golang中的哪个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文