go Verified current stable Not installed? Programming

Go / Show Package Documentation All Symbols Sources

Show Package Documentation All Symbols Sources

Go command to fetch documentation for all symbols in a specified package, showing source code.

$
Terminal
go doc -all -src <encoding/json>

When To Use

When needing to review the implementation details along with the documentation for better comprehension.

Pro Tip

Consider utilizing `go doc -all` for a broad overview that includes hidden internal types and functions.

Anatomy of Output

Understanding the result

Package encoding/json Package Header

Indicates the package being documented.

JSON represents the JSON format. Package Description

Describes the package functionality.

func Marshal(v interface{}) ([]byte, error) { Function Implementation

Demonstrates the actual source code for the function.

Troubleshooting

Common pitfalls

package not found

Solution: Check for typos in package name or ensure proper installation.

no documentation available

Solution: Confirm that the 'src' flag is supported in your Go version.

Error: Command failed with exit code 1

Solution: Ensure source code visibility for installed packages.

Command Breakdown

What each part is doing

go
Base Command
The executable that performs this operation. Here it runs Go before the shell applies any redirect operators.
<encoding/json>
encoding json
The value supplied for encoding json.
-all
Command Option
Tool-specific option used by this command invocation.
-src
Command Option
Tool-specific option used by this command invocation.

Alternative Approaches

Comparable commands in other tools

Alternative programming tools for the same job.