<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>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传