How to use the go doc command line


Doc prints the documentation comments associated with the item identified by its arguments (a package, const, func, type, var, method, or struct field) followed by a one-line summary of each of the first-level items "under" that item (package-level declarations for a package, methods for a type, etc.).

Show documentation for current package.
go doc
Show package docs for the doc command.
go doc cmd/doc
Show documentation for the encoding/json package.
go doc encoding/json
package json // import "encoding/json"
Package json implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions.

The go doc Commands and Options

  go <command> [arguments]

Show all the documentation for the package.
Respect case when matching symbols.
Treat a command (package main) like a regular package. Otherwise package main's exported symbols are hidden when showing the package's top-level documentation.
One-line representation for each symbol.
Show the full source code for the symbol. This will display the full Go source of its declaration and definition, such as a function definition (including the body), type declaration or enclosing const block. The output may therefore include unexported details.
Show documentation for unexported as well as exported symbols, methods, and fields.

Related Tags

#go# #go doc#