<p>To get the ast.Package, I currently use go/build.Default.Import to get the go/build.Package, then use go/parser.ParseDir with a filter function that only allows the build.Package.GoFiles files. That all seems to work, and everything seems to get parsed, but the Objects I mentioned above is nil.</p>
<p>(I need the package-level objects to get the iota count for const declarations from Object.Data.)</p>
<hr/>**评论:**<br/><br/>joetsai: <pre><p>You're in luck that I was working on improving godoc and I had to deal with this problem as well.</p>
<p><a href="https://play.golang.org/p/mYeyUEwHGJ" rel="nofollow">https://play.golang.org/p/mYeyUEwHGJ</a></p>
<p>One way is to use ast.NewPackage with a very simple package importer.</p>
<p>This is based on code found in github.com/golang/tools/godoc/server.go</p></pre>MadeThisForPython: <pre><p>I'd recommend you to go ask the #go-nuts channel on Freenode.</p></pre>
