godoc command document

In the previous article, we showed how to insert testable code into the go document, so how to use the go document. Let's find the corresponding document to learn. Let's learn the godoc command first.
The following is right https://pkg.go.dev/golang.org/x/tools/cmd/godoc Translation of.

Godoc will extract and generate documents for the Go program.

It will run a web server and display the documents as web pages.

godoc -http=:6060

use:

godoc [flag]

flags are:

-v
	Complex output mode
-timestamps=true
	Show timestamp on path list
-index
	Enable identifier and full-text search indexing
	(If not set -index You can't search the contents of the document)
-index_files=""
	glob The index file specified by the schema. If it is not empty, the indexes are read from these files in sorted order
-index_throttle=0.75
	Speed limit value of the index: setting it to 0 means that no time is allocated to the indexer(The indexer never terminates),1.0 Then means
	Creating indexes at full speed(During index creation, other goroutine Maybe not cpu time)
-index_interval=0
	The interval between index creation; A value of 0 will set it to 5 minutes, and a negative value will index only once at startup.
-play=false
	Enable playground
-links=true
	Link identifiers to their declarations
-write_index=false
	Write the index to the file; File name must use-index_files To specify
-maxresults=10000
	Maximum number of full-text search results that can be displayed
	(If maxresults<=0,(full text index will not be built)
-notes="BUG"
	regular expression matching note markers to show
	(e.g., "BUG|TODO", ".*")
-goroot=$GOROOT
	Go Root path of
-http=addr
	HTTP Address of the service(for example'127.0.0.1:6060'Or just':6060')
-analysis=type,pointer
	Comma separated list of analyses to display
	"type": Display identifier resolution,Type information, method set,'realization',And statically called
	"pointer": Exhibition channel Both ends, caller and dynamic are called(Significantly slower)
	See for details https://golang.org/lib/godoc/analysis/help.html
-templates=""
	The path contains optional template files. If this item is set, the corresponding path can provide an alternative $GOROOT/lib/godoc Template file in
-url=path
	Set the path to the corresponding path HTTP The requested data is output to standard output
-zip=""
	Specifies that the file system is provided zip File. If it is blank, it will not be enabled

By default, godoc will see the package s it finds in $goroot and $gopath (if set). You can change this behavior by providing another $goroot using the - goroot option.

When the - index option is set, a search index is maintained. This index will be created at startup.

The index contains identifiers and full-text search information (which can be searched through regular expressions). You can set the maximum number of full-text search results that can be displayed through - maxresults; If set to 0, there will be no full-text results, only identifier indexes, and no full-text search index will be created.

By default, godoc uses the system's GOOS/GOARCH. You can specify the URL parameters "GOOS" and "GOARCH" to set the output on the web page for the target system.

The display mode of the web page corresponding to godoc can be controlled through the "m"URL parameter. It accepts a comma separated flag list:

All presents documentation for all statements, not just those that are publicly available.
Methods shows all embedded methods, not just those anonymous fields that are not exposed
src shows the source code, not the extracted documents
flat shows a tiled (rather than compressed) list of directories, that is, the full path

For example, https://golang.org/pkg/math/big/?m=all Documents are generated for all (not just public) declarations of the big package.

By default, godoc handles files on the file system of the underlying OS. You can also provide a. Zip file through the - Zip option to let godoc process the file system represented by the zip. The file path stored in the. Zip file must use the diagonal bar ('/') as the path separator; And must be unrooted$ goroot (or - goroot) must be set to the. Zip file directory path containing the Go root path. For example, for a. Zip file created by the following command:

zip -r go.zip $HOME/go

You can run godoc like this:

godoc -http=:6060 -zip=go.zip -goroot=$HOME/go

Godoc documents are converted to HTML or text using go/doc package; If you want to know the extraction rules, see https://golang.org/pkg/go/doc/#ToHTML . Godoc will also show sample code that can be run by the testing package; See you https://golang.org/pkg/testing/#hdr-Examples . See "godoc: archiving Go code" to learn how to write great comments for godoc: https://golang.org/doc/articles/godoc_documenting_go_code.html.

Keywords: Go

Added by PastorHank on Thu, 16 Sep 2021 20:21:02 +0300