Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate HTML documents using `godoc`?

Tags:

go

I have written a small go program, and I want to generate standalone HTML documents from source code that can be viewed without godoc server. But I can't find any way to achieve it. if anyone could help me, I'll appreciate it.

like image 420
Zhe Chen Avatar asked Nov 23 '12 13:11

Zhe Chen


People also ask

How do you use Godoc tools?

Run go generate golang.org/x/tools/godoc/static so static/static.go picks up the change. Run go install golang.org/x/tools/cmd/godoc so the compiled godoc binary picks up the change. Run godoc -http=:6060 and view your changes in the browser. You may need to disable your browser's cache to avoid reloading a stale file.

How do I run Godoc?

Running a Godoc Server Once you have commented your code, you can run the godoc command in your terminal, from your project's code directory. The command above hosts your code documentation on localhost, or 127.0. 0.1. The port doesn't have to 6060; godoc will run on any unoccupied port.

What is go doc?

Overview. Godoc extracts and generates documentation for Go programs. It runs as a web server and presents the documentation as a web page.


2 Answers

A bit better form can by produced by:

godoc -url "http://localhost:6060/pkg/container/heap/" > page.html  

(I have godoc server running at :6060 and I'm not sure if that's a prerequisite).

The HTML would probably look better if combined with original CSS styles found in the Go repository by adjusting the produced HTML files to properly refer to it.

like image 178
zzzz Avatar answered Sep 28 '22 10:09

zzzz


This might not directly answer your question, but if you are planning to open source your project, you don't really have to generate HTML manually. Just make sure you have comments properly inserted in your source code, and use godoc.org( http://godoc.org/-/about ) to handle it.

It displays documentation for Go packages on Bitbucket, Github, Launchpad and Google Project Hosting.

Check this out for example: http://godoc.org/code.google.com/p/go.crypto/ssh

like image 33
Song Gao Avatar answered Sep 28 '22 10:09

Song Gao