How to use the go doc command line

Created

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

Usage: 
  go <command> [arguments]

Flags:
-all
Show all the documentation for the package.
-c
Respect case when matching symbols.
-cmd
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.
-short
One-line representation for each symbol.
-src
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.
-u
Show documentation for unexported as well as exported symbols, methods, and fields.

Related Tags

#go# #go doc#