TIL: go doc <type|func|pkg>

David Viramontes

David Viramontes
Today I discovered go doc <type|func|pkg>
; a useful tool for learning about the Go standard library or anything in your own project.
go help doc
# Example 1: Standard library function
go doc json.decode
package json // import "encoding/json"
func (dec *Decoder) Decode(v any) error
Decode reads the next JSON-encoded value from its input and stores it in the
value pointed to by v.
...
# Example 2: Your own project
cd path/to/project/types
go doc HomePageAsset
...
type HomePageAsset struct {
NotionFiles []notionapi.File `json:"notionFiles,omitempty"`
UUID string `json:"uuid,omitempty"`
Type string `json:"type,omitempty"`
Files []File `json:"files,omitempty"`
Align string `json:"align,omitempty"`
Width int `json:"width,omitempty"`
}
I don't do as much Go development these days but I always enjoy finding new tools in Go's standard tooling. Unlike some languages that require external tools or web browsers to access documentation, Go's approach of embedding documentation in the command line makes the development experience more efficient. This is especially helpful when working offline or when you need quick reference.
There is also godoc
for serving your own documentation.