Tool Recommendationgo-callvis

Go-callvis is a graphical representation of the call relationships of the GO program, which is especially useful when looking at complex projects.

Pro test, with the help of it to see the ancestral Golang code, headache is much better.

The installation

go get -u github.com/TrueFurby/go-callvis
# or
git clone https://github.com/TrueFurby/go-callvis.git
cd go-callvis && make install
Copy the code

run

  • Go 1.12 +
  • Graphviz:http://www.graphviz.org/download/ Mac can brew directly install graphviz

The address of the project: https://github.com/TrueFurby/go-callvis

Using the command

The command is extremely simple, requiring only a simple type:

go-callvis [OPTIONS] <main package>
Copy the code

Here the main package is the package containing the main function of the code, such as the project github.com/gusibi/onep…

The directory structure is:

. ├ ─ ─ the README. Md └ ─ ─ the SRC ├ ─ ─ DBS ├ ─ ─. Mod ├ ─ ─. Sum ├ ─ ─ idg │ ├ ─ ─ area_code. Go │ ├ ─ ─ idg. Go │ ├ ─ ─ idg_test. Go │ ├ ─ ─ Index. Go │ ├ ─ ─ index_test. Go │ ├ ─ ─ sort. Go │ ├ ─ ─ sort_test. Go │ ├ ─ ─ wr. Go │ └ ─ ─ wr_test. Go ├ ─ ─ main. Go └ ─ ─ sorteDBCopy the code

Where the SRC directory is a Go package, to run go-callVIS, you need to CD SRC/first, and then execute the command:

go-callvis  -group pkg,type md52id
Copy the code

Md52id is package name, declared in go.mod, pakage name is a mandatory parameter.

By default, the browser is opened to load the address http://localhost:7878

The image format is SVG. You can also add -format= PNG to display the image in PNG format

SVG is recommended. Content in SVG is interactive. For example, if you want to see the contents of the GIN package, you can click the corresponding module to see the details.

The result, if shown, is all of the package’s call relationships, arranged from left to right by the package’s call hierarchy. Above the second column is the gin framework code. If you do not want to see this part of the code, you can exclude it with ignore.

Command as follows:

go-callvis -group pkg,type -ignore github.com/gin-gonic/gin md52id
Copy the code

Here the gin package is named github.com/gin-gonic/gin instead of gin

If you want to drain idG packets, you can add them directly to the gin packets, separated by, (English comma).

Using the limit command gives the same result

go-callvis -group pkg,type -limit md52id md52id

The results obtained are:

To view the internal invocation relationship of the IDG package, run the focus command to specify the IDG package as follows:

go-callvis -focus=md52id/idg -group pkg,type -limit md52id md52id
Copy the code

The result is shown below:

For details, see github.com/TrueFurby/g…

Use go-CallVIS to visually display the calling relationship of code, especially useful for large project source code, such as gin Stagic package call relationship below:

As you can see intuitively from the picture,

  1. Static calls staticFS, and staticFS uses only the HEAD and GET methods.
  2. All HTTP Methods end up calling a handler to handle the response.

### go-callvis alternative usage

Go-callvis can also be used to evaluate whether the system design is reasonable and whether the code is clear. The following is the call diagram of Docker:

Original address: p1-jj.byteimg.com/tos-cn-i-t2…

It can be seen that the code structure is very clear, the call chain is relatively simple, and the project success is really perfect.

push

The following is shopee internal promotion advertisement, “Shenzhen, Singapore, Shanghai” positions are available, interested can leave a message or identify the TWO-DIMENSIONAL code delivery directly.

Finally, thanks to the girlfriend support and tolerance, than ❤️

Around the male can also enter the keywords for historical article: male number & small program | | concurrent design mode & coroutines

References

[1] go – callvis: github.com/TrueFurby/g…

[2] Go: golang.org/dl/

[3] Graphviz:www.graphviz.org/download/: www.graphviz.org/download/

[4] Project Location: github.com/TrueFurby/g… Github.com/TrueFurby/g…