在浏览器中本地查看软件包文档 [英] View package documentation locally in a browser
问题描述
我想在本地查看我的软件包文档的外观.也就是说,我想看到与您在 godoc.org 上看到的相同的东西,但是在本地看到.>
我在本地有一个简单的示例文件夹,但是无法使用.正确输出文本文档:
〜/code/go/gonotes(master)$ godoc.包装文件包gonotes导入."职能funb Blah()这是标题Blah用于测试的功能:-去文档-等等很好
但是,如果我运行 godoc -http =:6060
,并导航至 http://localhost:6060/
,我看到的内容基本上与我看到的相同在golang.com主页上. http://localhost:6060/gonotes
显示
lstat $ GOROOT/gonotes:没有这样的文件或目录
我误解了 -http
的工作原理吗?有什么办法可以在本地预览我的文档的http版本?
更新
将文件复制到 src/gonotes
然后运行:
GOPATH =/Users/jonah/code/go/gonotes godoc -http =:6060
,以便可以在/Users/jonah/code/go/gonotes/src/gonotes
中找到实际文件.
这有一个副作用,即没有显示默认的 GOPATH
中安装的任何第三方库,因此我仍然想找到一个解决方案,让我可以添加当前目录,照原样,无需向其中添加 src/curdir
,并且仍然可以显示它.
在 GOPATH
模式下
godoc -http
将提供所有可用软件包(包括标准库)的doc.不用担心,您自己的软件包就在其中,请再次查看.作为快捷方式,只需键入 http://localhost:6060/pkg/your/package
.
在模块感知模式下
GOPATH
和模块是互斥的,请参见弃用警告),因此现在,如果您想在 godoc
中本地查看模块的打包文档,则必须求助于将其源代码放在 src
中文件夹.
解决方法",用于查看模块的文档:
-
将存储库放入类似
/some/folder/src
的文件夹中 -
使用
godoc -goroot =/some/folder -http =:6060
启动godocs
查看相关问题:支持Go模块
也分组讨论: go 1.11 godoc工具是否具有模块意识'?
I want to see locally how my package documentation will look. That is, I want to see the same kind of thing you see on godoc.org, but locally.
I have a simple example folder locally, but I can't get it to work. It correctly outputs text documentation:
~/code/go/gonotes (master) $ godoc .
PACKAGE DOCUMENTATION
package gonotes
import "."
FUNCTIONS
func Blah()
Here is header
Blah is function being use to test:
- go documentation
- blah like things
It is nice
But if I run godoc -http=:6060
, and navigate to http://localhost:6060/
, I see essentially the same content I'd see on the golang.com homepage. http://localhost:6060/gonotes
displays
lstat $GOROOT/gonotes: no such file or directory
Am I misunderstanding how the -http
works? Is there any way to preview the http version of my docs locally?
UPDATE
I was able to get it to appear by copying the files into src/gonotes
and then running:
GOPATH=/Users/jonah/code/go/gonotes godoc -http=:6060
so that the actual files were available at /Users/jonah/code/go/gonotes/src/gonotes
.
This has the side effect of not showing any of the Third part libs installed in my default GOPATH
, so I'd still like to find a solution that just allows me to add the current directory, as is, without adding src/curdir
to it, and still have it show up.
In GOPATH
mode
godoc -http
will serve doc of all available packages, including the standard library. Worry not, your own packages are amongst them, just look again. As a shortcut, just type http://localhost:6060/pkg/your/package
.
In module-aware mode
GOPATH
and modules are mutually exclusive, see Go Modules does not recognize files under GOPATH. The godoc
tool is not module-aware, and it is being deprecated (see deprecation warning), so for now if you want to see your package docs of modules locally in godoc
, you have to resort to putting their sources in an src
folder.
"Workaround" for seeing docs of module's:
Put the repo in a folder like
/some/folder/src
Start godocs with
godoc -goroot=/some/folder -http=:6060
See related issue: support Go modules
Also groups discussion: Is the go 1.11 godoc tool 'module-aware'?
这篇关于在浏览器中本地查看软件包文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!