Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out which types implement which interface

Tags:

go

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?

like image 340
topskip Avatar asked Jan 29 '13 06:01

topskip


People also ask

Does an interface define a type?

When you define a new interface, you are defining a new reference data type. You can use interface names anywhere you can use any other data type name. If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface.


1 Answers

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.

like image 87
zzzz Avatar answered Oct 08 '22 22:10

zzzz