How to find out which types implement which interface

前端 未结 2 841
南笙
南笙 2020-12-29 06:46

Example:

In package io the type ByteReader defines an interface that wraps the method ReadByte() (c byte, err error).

What is the

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 07:09

    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] 
        
        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
    

提交回复
热议问题