title: How to programmatically retrieve the package path where a given type is declared?
body: <p>I am looking for a way to retrieve the package(s) installed locally which contain the declaration for a given type and the default package name.</p>
  
  <p>ie:</p>
  
  <pre><code>// FindPackagesForType returns the list of possible packages for a given type
  func FindPackagesForType(typeName string) []string {
      return []string {} // TODO: implement
  }
  
  func TestFindPackagesForType(t *testing.T) {
      assert.Contains(t, FindPackagesForType("io.Reader"), "io")
      assert.Contains(
          t,
          FindPackagesForType("types.Timestamp"),
          "github.com/gogo/protobuf/types",
      )
      assert.Contains(
          t,
          FindPackagesForType("types.ContainerCreateConfig"),
          "github.com/docker/docker/api/types",
      )
  }
  </code></pre>
  
  <p>I could try to retrieve all packages installed, and go through the AST in each looking for the declaration but if there is a solution which could do this more efficiently while also providing support for go modules I would like to use that.</p>
  
  <p>The reason for this is to improve a code generation tool. The idea is to let the user provide the name of a type and let the tool identify the most likely candidate the same way goimports adds missing imports.</p>