如何在GO中导出所有包的API名称

huangapple go评论72阅读模式
英文:

How to export all package API names in GO

问题

导出到api.txt文件,例如

fmt.Println(params...)
net.LookupIP(params...)
...

逐行

我使用这个来进行IDE自动补全

英文:

export to api.txt file,such as

fmt.Println(params...)
net.LookupIP(params...)
...

line by line

I using this to IDE autocomplete

答案1

得分: 2

正如其他人所说,gocode可能已经可以满足你的需求了。但是无论如何,要列出一个包的导出API,你可以使用go tool api <pkg>。例如:

$ go tool api runtime | grep func

pkg runtime, func Breakpoint()
pkg runtime, func CPUProfile() []byte
pkg runtime, func Caller(int) (uintptr, string, int, bool)
pkg runtime, func Callers(int, []uintptr) int
pkg runtime, func FuncForPC(uintptr) *Func
pkg runtime, func GC()
...
英文:

As others have said, gocode may well do what you want already. But anyway, to list the exported API of a package you can use go tool api &lt;pkg&gt;. e.g.

$ go tool api runtime | grep func

pkg runtime, func Breakpoint()
pkg runtime, func CPUProfile() []byte
pkg runtime, func Caller(int) (uintptr, string, int, bool)
pkg runtime, func Callers(int, []uintptr) int
pkg runtime, func FuncForPC(uintptr) *Func
pkg runtime, func GC()
...

答案2

得分: 1

在go存储库中已经有一个包含完整Go1 API的文本文件:http://code.google.com/p/go/source/browse/api/go1.txt

但是我建议您设置gocode(如果还没有的话,可以通过为您的IDE编写一个小插件来实现)。它为变量和包提供上下文敏感的自动补全,即使它们不是标准库的一部分,或者它们是用不同的名称导入的。

英文:

There is already a text file with the full Go1 API in the go repository:
http://code.google.com/p/go/source/browse/api/go1.txt

But I recommend you to set up gocode (maybe by writing a small plugin for your IDE if there isn't any already). It provides context-sensitive auto-completion for variables and packages, even if they aren't part of the standard library or when they have been imported with a different name.

答案3

得分: 0

解析软件包文件,遍历顶级域名(TLDs),收集导出和公开的标识符,你就几乎达到了 gocode 多年来的水平。

英文:

Parse the package files, walk the TLDs, collect the exported and exposed identifiers, and you are almost where gocode is for years.

huangapple
  • 本文由 发表于 2012年5月14日 12:59:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/10577707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定