dongxu4580 2019-05-27 21:11
浏览 72
已采纳

在浏览器中本地查看软件包文档

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.

  • 写回答

1条回答 默认 最新

  • duanpao6163 2019-05-28 12:30
    关注

    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'?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch