Gold is a Go local docs server, a Go docs generator, and a Go code reader. It tries to extract as much information as possible from Go code to help gophers understand, study and use Go packages.
- Demo of the generated docs for standard packages (please note that the demo site lacks of several features in the local server version).
- Please follow @Go100and1 to get the latest news of Gold.
go get -u go101.org/gold to install (and update) Gold.
GO111MODULE enviroment variable might need to be set as
on temporarily to utilize the
depending on your Go Toolchain version and the directory in which the installation command runs.)
Note, if the tool program name
gold conflicts with another tool with the same name you are using,
you can run any of the following commands to install Gold as a program with a different name:
- Go docs generator
go get -u go101.org/gold/godoge
- Go code reader
go get -u go101.org/gold/gocore
- Go local docs server
go get -u go101.org/gold/golds
If for any reason the
go get way doesn't work, you may also clone this project firstly, then run the
go install command in the respective program folders to install Gold as
- Supports listing exported types not only by alphabet, but also by popularity, which is good to understanding some packages exporting many types.
- Supports listing unexported types, which is good to read some packages.
- Rich package-level type/value information collection:
- Shows type implemention relations (demo 1 and demo 2).
- Shows method implementation relations (demo).
- Shows promoted selectors, even on unexported embedded fields (demo).
- Shows as-parameters-of and as-results-of function/method list (including interface methods).
- Shows the package-level value lists of a package-level type.
- Shows uses of package-level declared types/constants/variables/functions (by clicking the
- Smooth code view experiences (good for studying Go projects without opening IDEs):
- Click a local identifier to highlight all the occurences of the identifier.
- Click a use of a non-local identifier to jump to the declaration of the non-local identifier.
- Click the name of a field or a method in its declaration to show its uses (only for package-level named struct types now).
- Click the name of a method specified in an interface type declaration to show the methods implementing it (only for package-level named interface types now)..
- Shows code statistics (demo).
- Supports generating static HTML docs pages, to avoid rebuilding the docs later. This is good for package developers to host docs of their own packages. (The docs of standard packages are generated within about 7 seconds, and the docs of the kubernetes project packages are generated within about one minute.)
- All functionalities are implemented locally, no external websites are needed.
- Just fell free to open any number of pages in new browser windows as needed.
(NOTE: This tool is still in its early experimental phase. More new features will be added from time to time in future versions.)
Go Toolchain 1.13+ is needed to run Gold (and 1.14+ is needed to build Gold).
This project uses the golang.org/x/tools/go/packages package to parse code.
golang.org/x/tools/go/package package is great, but it also has a shortcoming: there are no ways to get module/package downloading/preparing progress.
All packages must compile okay to get their docs shown.
Only a code snapshot is analyzed. When code changes, a new analyzation is needed from scratch.
Testing packages are excluded currently.
Code examples in docs are not shown currently.
Start the docs server:
gold .to show docs of the package in the current directory (and all its dependency packages).
gold ./...to show docs of all packages under the current directory (and all their dependency packages).
gold stdto show docs of standard packages.
gold aPackageto show docs of the specified package (and all its dependency packages).
Each of the above commands will open a browser window automatically.
We can use the
-silent options to turn off the behavior.
Generate static HTML docs pages (the
-dir option is optional in this mode, its default value is
gold -gen -dir=generated .
gold -gen -dir=generated ./...
gold -gen -dir=generated std
The above commands will generated the full docs of specified packages. The following options are available to generate compact docs:
-nouses: don't generate identifier-uses pages (identifier-uses pages will occupy about 9/10 of the total page count and 2/3 of the full docs size).
-plainsrc: generate simpler source code pages (no highlighting and no code navigations to reduce the total page size by 1/6 of the full docs size).
The size of the docs generated by
gold -gen -nouses -plainsrc ./... is about 1/6 of
gold -gen ./....
-emphasize-wdpkgs option is used to list the packages within the working directory before other packages in the first page
(for HTML docs generation mode only).
We can run
gold -dir=. (or simply
gold) from the HTML docs generation directory to view the generated docs in browser.
(Gold also means Go local directory server. The
-silent options also work in this mode.)
gold command recognizes the
GOARCH environment variables.
The following results are got on a machine with an AMD-2200G CPU (4 cores 4 threads) and sufficient memory. Go Toolchain 1.14.3 is used in the analyzations.
Before running the
gold ./... command, the
go build ./... command is run to ensure that
all involved modules/packages are fetched to local machine and verify cgo tools (if needed) have been installed.
|Project||Package Count||Analyzation Time||Final Used Memory||Notes|
|go-sdl2 v0.4.4||47||1.3s||200M||(need run
|nats-server v2.1.7||136||2.3s||400M||(need run
|standard packages v1.14||199||2.6s||400M|
|etcd v3.4.7||391||3.5s||700M||(need run