我试图将特定的本地围棋文件作为文档网页提供服务,但无法实现.

official godoc documentation人说:

使用-http标志(即godoc命令),它作为Web服务器运行,并将文档显示为网页.

user_me$ godoc -http=:6060

这确实会创建类似于go页面的内容,但它不会呈现我想要呈现的特定文件.所以我试着提供我想要的文件名:

user_me$ godoc -http=:6000 hello.go

但是,它只回复说:

usage: godoc package [name ...]
    godoc -http=:6060
  -ex=false: show examples in command line mode
  -goroot="/usr/local/go": Go root directory
  -html=false: print HTML in command-line mode
  -http="": HTTP service address (e.g., ':6060')
  -httptest.serve="": if non-empty, httptest.NewServer serves on this address and blocks
  -index=false: enable search index
  -index_files="": glob pattern specifying index files;if not empty, the index is read from these files in sorted order
  -index_throttle=0.75: index throttle value; 0.0 = no time allocated, 1.0 = full throttle
  -links=true: link identifiers to their declarations
  -maxresults=10000: maximum number of full text search results shown
  -notes="BUG": regular expression matching note markers to show
  -play=false: enable playground in web interface
  -q=false: arguments are considered search queries
  -server="": webserver address for command line searches
  -src=false: print (exported) source in command-line mode
  -tabwidth=4: tab width
  -templates="": directory containing alternate template files
  -timestamps=false: show timestamps with directory listings
  -url="": print HTML for named URL
  -v=false: verbose mode
  -write_index=false: write index to a file; the file name must be specified with -index_files
  -zip="": zip file providing the file system to serve; disabled if empty

我还试过:

user_me$ godoc -url="localhost:8080" hello.go

但没用.

我还试过:

godoc -server=localhost:8080 hello.go

但它的回答是:

2014/07/01 10:45:56 open /usr/local/go/src/pkg/hello.go: no such file or directory

我甚至试着自己生成html:

godoc -html hello.go > hello.html

与上述错误相同.

我还try 了(因为它抱怨pkg目录中没有文件):

godoc -html -goroo=$GOPATH hello.go > hello.html

最后,我放弃了.我不知道godoc是怎么运作的.我安装了hello.go程序,这样我就可以在工作区的pkg文件中找到一些东西.如何生成包含代码文档的网页?

推荐答案

godoc操作的是包名和类型名,而不是文件名.

例如,要了解io/ioutil个套餐:

  • 文本输出:godoc io/ioutil

  • ReadAll函数:godoc io/ioutil ReadAll

  • HTML格式:godoc -html io/ioutil ReadAll

  • 在浏览器中:

    • godoc -http=:6060
    • 单击包,然后从该位置导航
    • 或者直接转到http://localhost:6060/pkg/io/ioutil#ReadAll

要查看自己代码的文档,必须将其包含在GOPATH中.

假设你的GOPATH包括$HOME/go/src,你感兴趣的文件是$HOME/go/src/hey/world/doc.go,你会运行:

godoc hey/world

.或在HTTP模式下启动godoc并浏览到http://localhost:6060/pkg/hey/world

Go相关问答推荐

运行add. inf,这样我们就可以在app.conf中使用. inf参数了?

Go Regexp:匹配完整的单词或子字符串,或者根本不匹配

Wamtime Memory中的‘Offset’是什么?Read?

什么东西逃到了堆里?

如何在gofiber/websocket/v2中设置状态代码和原因

该文件位于模块.内,该模块不包含在您的工作区中

我应该先解锁然后再广播吗?

Go 中的 Azure JWT 验证不起作用

对 CSV 进行单元测试失败

go version -m 输出中的箭头符号=>是什么意思?

为什么时间很短.睡眠时间比基准测试中要求的(约 300 ns)长?

如何在Go中替换符号并使下一个字母大写

将接口方法的参数限制为几个允许的 struct ?

Golang Echo Labstack 如何在模板视图中调用函数/方法

httprouterhttp.HandlerFunc() 是如何工作的?

将 Simple Go Web 应用程序部署到 Elastic Beanstalk

函数参数的判断顺序是什么?

如何解决在mac m1中运行gcc失败退出状态1?

Go 语言的select语句

Go 和 Java 使用用户空间线程这一事实是否意味着您不能真正利用多核?