使用-http标志(即godoc命令),它可以作为网络服务器运行,并以网页形式显示文档. With the -http flag (i.e. the godoc command), it runs as a web server and presents the documentation as a web page.user_me$ godoc -http=:6060这确实会创建类似于go页面的内容,但是不会呈现我要呈现的特定文件.因此,我尝试提供所需文件的名称:This does create something similar as the go page but it does not render the specific file that I want to render. So I tried to provide the name of the file I wanted: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本身:I even tried just generating the html thing itself:godoc -html hello.go > hello.html与上述错误相同.我也尝试过(因为它抱怨pkg目录中没有文件):I also tried (since it was complaining that there was no file in the pkg dir):godoc -html -goroo=$GOPATH hello.go > hello.html最后,我放弃了.我不知道这godoc的工作原理.我安装了hello.go程序,以便在工作区的pkg文件中有文件.您如何使用代码文档生成网页?At the end, I gave up. I don't know how this godoc thing works. I installed the hello.go program so that I there was something in the pkg file in the workspace. How do you generate a webpage with your documentation for your code?推荐答案 godoc对程序包和类型名(而非文件名)进行操作.godoc operates on package and type names, not filenames.例如,要了解 io/ioutil 软件包: 文本输出: godoc io/ioutil 只需 ReadAll 函数: godoc io/ioutil ReadAll : godoc -html io/ioutil ReadAll 在浏览器中: godoc -http =:6060 点击包"并从那里导航或直接转到 http://localhost:6060/pkg/io/ioutil#ReadAll 要查看您自己的代码的文档,必须将其包含在您的 GOPATH 中.To view documentation for your own code, it has to be included in your GOPATH.假设您的 GOPATH 包含 $ HOME/go/src ,而您感兴趣的文件是 $ HOME/go/src/hey/world/doc.go ,您将运行:Suppose your GOPATH includes $HOME/go/src, and the file you are interested in is $HOME/go/src/hey/world/doc.go, you would run:godoc hey/world ...或以HTTP模式启动godoc并浏览到 http://localhost:6060/pkg/hey/world ...or start godoc in HTTP mode and browse to http://localhost:6060/pkg/hey/world 这篇关于您如何使用godoc作为网页为go程序提供简单的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-26 08:46