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

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

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据