【问题标题】:How to use godoc to open the docs for your current package?如何使用 godoc 打开当前包的文档?
【发布时间】:2021-09-19 08:38:36
【问题描述】:

我只想显示一个包的文档。正如其他答案所说,我已经尝试过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

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

【问题讨论】:

  • 这个错误信息实际上给了你很多信息。您是否尝试阅读或按照建议的步骤操作?

标签: go godoc


【解决方案1】:

如果您只需要命令行帮助,请使用go docgo doc -all

如果要浏览器版本,那就有点奇怪了。如果您的包位于名为 something 的文件夹中,则需要移动该文件夹,使其如下所示:

godoc/src/something

然后,转到godoc 文件夹,然后运行

godoc -goroot .

然后,浏览到localhost:6060

【讨论】:

  • godoc/src 目录应该在我的 GOPATH 上的什么位置?我的包裹在$GOPATH/src/github.com/user/repo
  • If your package is in a folder called something, you need to move the folder 你的意思是cd 到文件系统上的包位置吗?
猜你喜欢
  • 2020-07-01
  • 2019-04-10
  • 2012-11-11
  • 1970-01-01
  • 2011-01-27
  • 1970-01-01
  • 2018-08-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多