LinuxCommandLibrary

go-doc

Display Go package documentation

TLDR

View documentation for the current package

$ go doc
copy

Show package documentation and exported symbols
$ go doc [encoding/json]
copy

Show also documentation of symbols
$ go doc -all [encoding/json]
copy

Show also sources
$ go doc -all -src [encoding/json]
copy

Show a specific symbol
$ go doc -all -src [encoding/json.Number]
copy

SYNOPSIS

go doc [package] [symbol]

PARAMETERS

package
    The name of the Go package to view documentation for. Example: go doc fmt

symbol
    The name of a specific symbol (function, type, variable, etc.) within a package to view documentation for. Example: go doc fmt.Printf

-all
    Show all documentation for the package, including unexported symbols. (Usually not recommended).

-src
    Show the source code of the symbol along with its documentation.

-u
    Show documentation for unexported symbols if package is not part of standard library.

-cmd
    Treat the package as a command. Useful for viewing documentation of command-line tools.

DESCRIPTION

The go doc command provides access to documentation for Go packages and symbols. It can display documentation for standard library packages, third-party packages, and your own code. It extracts documentation from source code comments and presents it in a readable format. You can specify a package name to view its overall documentation or a specific symbol (function, type, variable, etc.) to view its documentation.

The go doc command is a crucial tool for understanding Go code and libraries. It eliminates the need to manually browse source code to find documentation. It supports both command-line and web-based viewing. Its capabilities extends to exploring the documentation for identifiers within the current package, identifiers of other packages, and associated methods for those identifiers.

EXAMPLES

  • View documentation for the 'fmt' package: go doc fmt
  • View documentation for the 'Printf' function in the 'fmt' package: go doc fmt.Printf
  • View documentation of a method go doc time.Time.Format

DOCUMENTATION CONVENTIONS

Go documentation is extracted from comments directly preceding the function, type, or variable declaration. These comments should be formatted using standard Go conventions, with the first sentence of each comment providing a brief summary.

SEE ALSO

godoc(1), go(1)

Copied to clipboard