How to find out which types implement which interface

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.


There are now better ways to do this than simply searching.

Go Oracle has an implements query that will show which types implement a particular interface, and which interfaces a particular type implements.

Additionally, here is a tool that claims to offer the same functionality: https://github.com/dominikh/implements.

2020 Update: The official Go language server, gopls, also has support for this query:

    ➜ gopls implementation -h
    display selected identifier's implementation
    
    Usage: implementation [flags] <position>
    
    Example:
    
      $ # 1-indexed location (:line:column or :#offset) of the target identifier
      $ gopls implementation helper/helper.go:8:6
      $ gopls implementation helper/helper.go:#53

Tags:

Go