GithubHelp home page GithubHelp logo

doytsujin / gold Goto Github PK

View Code? Open in Web Editor NEW

This project forked from go101/golds

0.0 1.0 0.0 1.33 MB

An experimental Go local docs server/generator and code reader implemented with some fresh ideas.

Home Page: https://go101.org/article/tool-gold.html

License: MIT License

Go 100.00%

gold's Introduction

Gold is a Go local docs server, Go docs generator, and a Go code reader. It tries to extract as much information as possible from Go code to help gophers use and study Go packages.

Installation

Run go get -u go101.org/gold to install (and update) Gold.

Notes:

  • If the tool name gold conflicts with another tool with the same name you are using, you can run go get -u go101.org/gold/godoge instead to install Gold as godoge.
  • The GO111MODULE enviroment variable might need to be set as on to utilize the GOPROXY setting, depending on your Go Toolchain version and the directory in which the installation command runs.

Features

  • Supports listing exported types not only by alphabet, but also by popularity, which is good to understanding some packages exporting many types.
  • Rich type information collection:
    • Shows type implemention relations (demo 1 and demo 2).
    • Shows promoted selectors, even on unexported embedded fields (demo).
    • Shows as-parameters-of and as-results-of funciton/method list (including interface methods).
  • 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 reference to a non-local identifier to jump to the declaration of the non-local identifier, and fell free to open pages in new browser windows as needed.
  • Shows code statistics (demo).
  • Supports generating static HTML docs pages, to avoid rebuilding the docs later. And this is good for package developers to host docs of their packages.
  • All functionalities are implemented locally, no external websites are needed.
  • JavaScript-off friendly. No tracing, no auto external websites visiting.

(NOTE: This tool is still in its early experimental phase. More new features will be added from time to time in future versions.)

Limitations

Go Toolchain 1.13+ is needed to build and run Gold.

This project uses the golang.org/x/tools/go/packages package to parse code. The golang.org/x/tools/go/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.

Usage

Start the docs server:

  • Run gold . or gold to show docs of the package in the current directory (and all its dependency packages).
  • Run gold ./... to show docs of all packages under the current directory (and all their dependency packages).
  • Run gold std to show docs of standard packages.

Each of the above commands will open a browser window automatically. We can use the -s or -silent flags to turn off the behavior.

Generate static HTML docs pages (the -dir flag is optional in this mode, its default value is .):

  • gold -gen -dir=generated
  • gold -gen -dir=generated ./...
  • gold -gen -dir=generated std

We can run gold -dir=. from the HTML docs generation directory to view the generated docs.

Analyzation Cases

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 go mod init github.com/veandco/go-sdl2 before running Gold)
bolt v1.3.1 51 1.6s 140M
tview rev:823f280 102 2s 200M (run gold . instead of gold ./...)
gorilla/websocket v1.4.2 118 1.8s 337M
gio rev:3314696 119 3.1s 1G
nats-server v2.1.7 136 2.3s 400M (need run go mod vendor before running Gold)
badger v2.0.3 145 2.2s 350M
Gold v0.0.1 151 2.5s 400M (run gold . instead of gold ./...)
pion/webrtc v2.2.9 189 2.1s 400M
goleveldb v1.0.0 193 2.7s 600M
standard packages v1.14 199 2.6s 400M
ebiten v1.11.1 214 2.1s 472M
tailscale v0.98.0 275 2.5s 539M
etcd v3.4.7 391 3.5s 700M (need run go mod vendor before running Gold)
go-ethereum v1.9.14 459 5.5s 1.3G
minio RELEASE.2020-05-16T01-33-21Z 639 5.1s 1.2G
terraform v0.12.25 777 5.7s 1.5G
consul v1.7.3 803 7.2s 1.9G
vitess v6.0.20-20200525 905 7.1s 1.7G
istio 1.6.0 1860 10.7s 2.8G
kubernetes v1.18.2 2821 16.3s 4G

There are still some famous projects failing to build (with the go build ./... command, at May 27th, 2020), such as docker, gvisor and traefik, so Gold is unable to build docs for them.

There are also some projects not using go modules, such as hashicorp/nomad and openshift/origin, and GOPROXY doesn't take effect for the go mod init command (as of Go Toolchain 1.14), so I couldn't build docs for these projects on my machine (this is my network problem, it might work on your machine).

gold's People

Contributors

go101 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.