Skip to content

Tool to visualize the graph of embedded structs in Go projects

License

Notifications You must be signed in to change notification settings

gorundebug/embedded-struct-visualizer

 
 

Repository files navigation

Visualize a hierarchy of embedded Go structs

This tool scans a directory of Go source code files to create a visualization of struct embedding in the project. This can be useful for navigating the data structures of complex projects, or identifying dependencies on particular structures.

Example

This figure would be generated from the input file below:

visualizer screenshot

package main

import (
	"time"
	"domain.tld/user"
)

type A struct {
	B
	C map[string]D
}

type B struct {
	E, F  string
	G     user.Status
	Timer H
}

type D struct {
	I uint64
}

type H struct {
	Timer time.Ticker
	J     chan D
}

Usage

Install:

$ go install github.com/davidschlachter/embedded-struct-visualizer@latest

Or,

$ git clone https://github.com/davidschlachter/embedded-struct-visualizer
$ cd embedded-struct-visualizer
$ go install github.com/davidschlachter/embedded-struct-visualizer

Options:

$ embedded-struct-visualizer -h
Usage: embedded-struct-visualizer [OPTIONS] DirToScan
If the directory to scan is not provided, it defaults to './'
OPTIONS:
  -out <file>  path to output file (default: write to stdout)
  -rankdir <direction> graphs direction (default: LR, enum: TB,LR,BT,RL)
  -exclude-pkg path to exclude pkg config file, format(default: empty):
     eg: exclude gopkg.in/guregu/null.v3 and models/MyStuct
       prefix:null.
       models.MyStuct
  -v           verbose logging

To open a generated DOT file, you could use Graphviz or xdot.

About

Tool to visualize the graph of embedded structs in Go projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%