如何获取一个 Golang 包中所有可用的函数?

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

How do I get all the functions that are available in a Golang package?

问题

你可以使用Go语言的文档工具来获取一个包中所有可用的函数列表。在你提到的情况下,你可以使用以下命令来获取time包中的所有函数:

go doc time

这将输出time包的文档,其中包括所有可用的函数列表。你还可以使用go doc命令来获取其他包的函数列表,只需将包的导入路径作为参数传递给该命令即可。

另外,你还可以在Go语言官方网站上查看包的文档。在网站上,你可以找到每个包的详细文档,其中包括所有可用的函数和类型。对于time包,你可以在https://pkg.go.dev/time页面上找到完整的文档。

希望这些提示对你有帮助!

英文:

How can I get all list of functions that are available in the package, For example in time package, When I click the link to list the package functions it is listing only a few functions.

There are functions which are documented under types which are not listed under the package functions.

For example:

func ParseDuration(s string) (Duration, error)

Which appears under type Duration is not listed. I believe this is the case for all the packages in Golang, if this is the case, how can I find out all package functions quickly?

Do you have some tips? Thanks in advance, Naga

答案1

得分: 4

使用go doc命令来列出一个包中的函数:

go doc -short time | grep "func "
英文:

Use the go doc command to list functions in a package:

go doc -short time | grep "func "

huangapple
  • 本文由 发表于 2022年7月19日 05:08:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/73028650.html
匿名

发表评论

匿名网友

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

确定