title: Go parser not detecting Doc comments on struct type
body: <p>I am trying to read the assocated Doc comments on a struct type using Go’s <a href="http://golang.org/pkg/go/parser/" rel="noreferrer">parser</a> and <a href="http://golang.org/pkg/go/ast/" rel="noreferrer">ast</a> packages. In this example, the code simply uses itself as the source.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "go/ast"
      "go/parser"
      "go/token"
  )
  
  // FirstType docs
  type FirstType struct {
      // FirstMember docs
      FirstMember string
  }
  
  // SecondType docs
  type SecondType struct {
      // SecondMember docs
      SecondMember string
  }
  
  // Main docs
  func main() {
      fset := token.NewFileSet() // positions are relative to fset
  
      d, err := parser.ParseDir(fset, "./", nil, parser.ParseComments)
      if err != nil {
          fmt.Println(err)
          return
      }
  
      for _, f := range d {
          ast.Inspect(f, func(n ast.Node) bool {
              switch x := n.(type) {
              case *ast.FuncDecl:
                  fmt.Printf("%s:\tFuncDecl %s\t%s\n", fset.Position(n.Pos()), x.Name, x.Doc)
              case *ast.TypeSpec:
                  fmt.Printf("%s:\tTypeSpec %s\t%s\n", fset.Position(n.Pos()), x.Name, x.Doc)
              case *ast.Field:
                  fmt.Printf("%s:\tField %s\t%s\n", fset.Position(n.Pos()), x.Names, x.Doc)
              }
  
              return true
          })
      }
  }
  </code></pre>
  
  <p>The comment docs for the func and fields are output no problem, but for some reason the ‘FirstType docs’ and ‘SecondType docs’ are nowhere to be found. What am I missing? Go version is 1.1.2.</p>
  
  <p>(To run the above, save it into a main.go file, and <code>go run main.go</code>)</p>