How to use godoc to open the docs for your current package?

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

How to use godoc to open the docs for your current package?

问题

我想要显示一个包的文档。我尝试了godoc github.com/user/repo,但是我得到了以下错误:

$ godoc github.com/user/repo
Unexpected arguments. Use "go doc" for command-line help output instead. For example, "go doc fmt.Printf".
usage: godoc -http=localhost:6060
  -analysis string
    	comma-separated list of analyses to perform when in GOPATH mode (supported: type, pointer). See https://golang.org/lib/godoc/analysis/help.html
  -goroot string
    	Go root directory (default "/usr/local/Cellar/go/1.16.5/libexec")
  -http string
    	HTTP service address (default "localhost:6060")
  -index
    	enable search index
  -index_files string
    	glob pattern specifying index files; if not empty, the index is read from these files in sorted order
  -index_interval duration
    	interval of indexing; 0 for default (5m), negative to only index once at startup
  -index_throttle float
    	index throttle value; 0.0 = no time allocated, 1.0 = full throttle (default 0.75)
  -links
    	link identifiers to their declarations (default true)
  -maxresults int
    	maximum number of full text search results shown (default 10000)
  -notes string
    	regular expression matching note markers to show (default "BUG")
  -play
    	enable playground
  -templates string
    	load templates/JS/CSS from disk in this directory
  -timestamps
    	show timestamps with directory listings
  -url string
    	print HTML for named URL
  -v	verbose mode
  -write_index
    	write index to a file; the file name must be specified with -index_files
  -zip string
    	zip file providing the file system to serve; disabled if empty

我应该如何使用godoc只显示我的包的文档?

英文:

I want to display the docs only for a package. I've tried godoc github.com/user/repo as other answers says but I get the following error:

$ godoc github.com/user/repo
Unexpected arguments. Use "go doc" for command-line help output instead. For example, "go doc fmt.Printf".
usage: godoc -http=localhost:6060
  -analysis string
    	comma-separated list of analyses to perform when in GOPATH mode (supported: type, pointer). See https://golang.org/lib/godoc/analysis/help.html
  -goroot string
    	Go root directory (default "/usr/local/Cellar/go/1.16.5/libexec")
  -http string
    	HTTP service address (default "localhost:6060")
  -index
    	enable search index
  -index_files string
    	glob pattern specifying index files; if not empty, the index is read from these files in sorted order
  -index_interval duration
    	interval of indexing; 0 for default (5m), negative to only index once at startup
  -index_throttle float
    	index throttle value; 0.0 = no time allocated, 1.0 = full throttle (default 0.75)
  -links
    	link identifiers to their declarations (default true)
  -maxresults int
    	maximum number of full text search results shown (default 10000)
  -notes string
    	regular expression matching note markers to show (default "BUG")
  -play
    	enable playground
  -templates string
    	load templates/JS/CSS from disk in this directory
  -timestamps
    	show timestamps with directory listings
  -url string
    	print HTML for named URL
  -v	verbose mode
  -write_index
    	write index to a file; the file name must be specified with -index_files
  -zip string
    	zip file providing the file system to serve; disabled if empty

How should I use godocs to display only the docs for my package?

答案1

得分: 2

如果你只想要命令行帮助,可以使用go docgo doc -all命令。

如果你想要浏览器版本的帮助,稍微有点奇怪。如果你的包在一个名为something的文件夹中,你需要将该文件夹移动到如下所示的位置:

godoc/src/something

然后,进入godoc文件夹,并运行以下命令:

godoc -goroot .

然后,浏览到localhost:6060

英文:

If you just want the command line help, do go doc or go doc -all.

If you want the browser version, it's a little strange. If your package is in a folder called something, you need to move the folder so that it looks like this:

godoc/src/something

Then, go to the godoc folder, and run

godoc -goroot .

Then, browse to localhost:6060.

huangapple
  • 本文由 发表于 2021年7月9日 06:02:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/68309080.html
匿名

发表评论

匿名网友

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

确定