• Stars
    star
    909
  • Rank 50,251 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Visualize Go Dependency Trees

depth

GoDocย  Build Statusย  Go Report Cardย  Coverage Status

depth is tool to retrieve and visualize Go source code dependency trees.

Install

Download the appropriate binary for your platform from the Releases page, or:

go get github.com/KyleBanks/depth/cmd/depth

Usage

depth can be used as a standalone command-line application, or as a package within your own project.

Command-Line

Simply execute depth with one or more package names to visualize. You can use the fully qualified import path of the package, like so:

$ depth github.com/KyleBanks/depth/cmd/depth
github.com/KyleBanks/depth/cmd/depth
  โ”œ encoding/json
  โ”œ flag
  โ”œ fmt
  โ”œ io
  โ”œ log
  โ”œ os
  โ”œ strings
  โ”” github.com/KyleBanks/depth
    โ”œ fmt
    โ”œ go/build
    โ”œ path
    โ”œ sort
    โ”” strings
12 dependencies (11 internal, 1 external, 0 testing).

Or you can use a relative path, for example:

$ depth .
$ depth ./cmd/depth
$ depth ../

You can also use depth on the Go standard library:

$ depth strings
strings
  โ”œ errors
  โ”œ internal/bytealg
  โ”œ io
  โ”œ sync
  โ”œ unicode
  โ”œ unicode/utf8
  โ”” unsafe
7 dependencies (7 internal, 0 external, 0 testing).

Visualizing multiple packages at a time is supported by simply naming the packages you'd like to visualize:

$ depth strings github.com/KyleBanks/depth 
strings
  โ”œ errors
  โ”œ internal/bytealg
  โ”œ io
  โ”œ sync
  โ”œ unicode
  โ”œ unicode/utf8
  โ”” unsafe
7 dependencies (7 internal, 0 external, 0 testing).
github.com/KyleBanks/depth
  โ”œ bytes
  โ”œ errors
  โ”œ go/build
  โ”œ os
  โ”œ path
  โ”œ sort
  โ”” strings
7 dependencies (7 internal, 0 external, 0 testing).

-internal

By default, depth only resolves the top level of dependencies for standard library packages, however you can use the -internal flag to visualize all internal dependencies:

$ depth -internal strings
strings
  โ”œ errors
  โ”‚ โ”” internal/reflectlite
  โ”‚   โ”œ internal/unsafeheader
  โ”‚   โ”‚ โ”” unsafe
  โ”‚   โ”œ runtime
  โ”‚   โ”‚ โ”œ internal/abi
  โ”‚   โ”‚ โ”‚ โ”” unsafe
  โ”‚   โ”‚ โ”œ internal/bytealg
  โ”‚   โ”‚ โ”‚ โ”œ internal/cpu
  โ”‚   โ”‚ โ”‚ โ”” unsafe
  โ”‚   โ”‚ โ”œ internal/cpu
  โ”‚   โ”‚ โ”œ internal/goexperiment
  โ”‚   โ”‚ โ”œ runtime/internal/atomic
  โ”‚   โ”‚ โ”‚ โ”” unsafe
  โ”‚   โ”‚ โ”œ runtime/internal/math
  โ”‚   โ”‚ โ”‚ โ”” runtime/internal/sys
  โ”‚   โ”‚ โ”œ runtime/internal/sys
  โ”‚   โ”‚ โ”” unsafe
  โ”‚   โ”” unsafe
  โ”œ internal/bytealg
  โ”œ io
  โ”‚ โ”œ errors
  โ”‚ โ”” sync
  โ”‚   โ”œ internal/race
  โ”‚   โ”‚ โ”” unsafe
  โ”‚   โ”œ runtime
  โ”‚   โ”œ sync/atomic
  โ”‚   โ”‚ โ”” unsafe
  โ”‚   โ”” unsafe
  โ”œ sync
  โ”œ unicode
  โ”œ unicode/utf8
  โ”” unsafe
18 dependencies (18 internal, 0 external, 0 testing).

-max

The -max flag limits the dependency tree to the maximum depth provided. For example, if you supply -max 1 on the depth package, your output would look like so:

$ depth -max 1 github.com/KyleBanks/depth/cmd/depth
github.com/KyleBanks/depth/cmd/depth
  โ”œ encoding/json
  โ”œ flag
  โ”œ fmt
  โ”œ io
  โ”œ log
  โ”œ os
  โ”œ strings
  โ”” github.com/KyleBanks/depth
7 dependencies (6 internal, 1 external, 0 testing).

The -max flag is particularly useful in conjunction with the -internal flag which can lead to very deep dependency trees.

-test

By default, depth ignores dependencies that are only required for testing. However, you can view test dependencies using the -test flag:

$ depth -test strings
strings
  โ”œ bytes
  โ”œ errors
  โ”œ fmt
  โ”œ internal/bytealg
  โ”œ internal/testenv
  โ”œ io
  โ”œ math/rand
  โ”œ reflect
  โ”œ strconv
  โ”œ sync
  โ”œ testing
  โ”œ unicode
  โ”œ unicode/utf8
  โ”” unsafe
14 dependencies (14 internal, 0 external, 7 testing).

-explain target-package

The -explain flag instructs depth to print import chains in which the target-package is found:

$ depth -explain strings github.com/KyleBanks/depth/cmd/depth
github.com/KyleBanks/depth/cmd/depth -> strings
github.com/KyleBanks/depth/cmd/depth -> github.com/KyleBanks/depth -> strings

-json

The -json flag instructs depth to output dependencies in JSON format:

$ depth -json github.com/KyleBanks/depth/cmd/depth
{
  "name": "github.com/KyleBanks/depth/cmd/depth",
  "deps": [
    {
      "name": "encoding/json",
      "internal": true,
      "deps": null
    },
    ...
    {
      "name": "github.com/KyleBanks/depth",
      "internal": false,
      "deps": [
        {
          "name": "go/build",
          "internal": true,
          "deps": null
        },
        ...
      ]
    }
  ]
}

Integrating With Your Project

The depth package can easily be used to retrieve the dependency tree for a particular package in your own project. For example, here's how you would retrieve the dependency tree for the strings package:

import "github.com/KyleBanks/depth"

var t depth.Tree
err := t.Resolve("strings")
if err != nil {
    log.Fatal(err)
}

// Output: "'strings' has 4 dependencies."
log.Printf("'%v' has %v dependencies.", t.Root.Name, len(t.Root.Deps)) 

For additional customization, simply set the appropriate flags on the Tree before resolving:

import "github.com/KyleBanks/depth"

t := depth.Tree {
  ResolveInternal: true,
  ResolveTest: true,
  MaxDepth: 10,
}


err := t.Resolve("strings")

Author

depth was developed by Kyle Banks.

License

depth is available under the MIT license.

More Repositories

1

goggles

๐Ÿ”ญ Goggles is a cross-platform GUI for your $GOPATH!
Go
671
star
2

XOREncryption

XOR encryption implementations for several languages.
Visual Basic .NET
348
star
3

scene-ref-attribute

Unity C# attribute for serializing component and interface references within the scene or prefab during OnValidate.
C#
275
star
4

IconEditText

Reusable view for displaying an ImageView with an EditText for Android 4.0 +
Java
265
star
5

conways-gol

Conway's Game of Life implemented with Go and OpenGL.
Go
110
star
6

ReactCalculator

A React Native tutorial where you'll write a calculator app for Android and iOS.
JavaScript
77
star
7

goodreads

Goodreads API client written in Go.
Go
68
star
8

go-kit

A collection of Go utility packages intended to be independent and reusable.
Go
60
star
9

AnimatedListView

An Android ListView implementation that animates views into place, similar to the Google Plus app on Android
Java
49
star
10

shader-pong

HLSL
46
star
11

dockerstats

Monitor Docker container statistics, including memory and CPU usage, from Go!
Go
42
star
12

kylewbanks.com-AndroidApp

An Android app that loads and displays posts from kylewbanks.com
Java
34
star
13

iOS-Enterprise-Distribution-Plist-Generator

Shell
22
star
14

GSONAndroidSample

A simple application that uses the GSON to fetch and parse JSON into Java models for Android
Java
22
star
15

commuter

Commute times on the command line!
Go
20
star
16

AsyncImageDownloader

Very simple asynchronous image downloader for iOS and Mac OS
Objective-C
15
star
17

tensorflow-checkpoints

This repository demonstrates how you could use a simple convolutional neural network classifier to determine game save checkpoints from a video game screenshot.
Python
14
star
18

conways-gol-cnn

A convolutional neural network that plays Conway's Game of Life.
Jupyter Notebook
11
star
19

tensorflow-docker-retrain

Retraining of InceptionV3 or MobileNet using TensorFlow and Docker.
Dockerfile
11
star
20

modoc

modoc is the Master Of Document Organization and Compilation
Go
11
star
21

s3fs

S3 File Explorer written in Go
Go
10
star
22

animated-line-graph-view

๐Ÿ“ˆ An animated line graph view for Android.
Java
9
star
23

unimation

Animation toolbox for Unity 2D and 3D games.
C#
6
star
24

DeployAutoScalingGroup

Shell
6
star
25

awsprof

Manage AWS Access and Secret Key Environment Variables using Profile Names
Go
6
star
26

sql-jekyll-migration

Go
5
star
27

banks-residence

Various home automation related projects.
Go
5
star
28

overlap-shader

5
star
29

react-native-tutorial-reactusers

React Native Tutorial for AnDevCon.com
JavaScript
5
star
30

lambda-uploader

A Node.js module for uploading a source directory to AWS Lambda
JavaScript
4
star
31

Rdio-Controller-for-Leap-Motion

A simple Rdio controller built for the Leap Motion
Objective-C
4
star
32

unity-git-sample

Sample project with Unity
4
star
33

RESTCache

An In-Memory Cache with an HTTP(s) Interface
JavaScript
4
star
34

1rm

A very small command-line tool to calculate your One-Rep Max (1RM).
Go
3
star
35

dockerton

Dockerton wraps the core functionality of Docker into an easy-to-use Node.js library.
JavaScript
3
star
36

thanos

Go
3
star
37

metroid

A fully managed system for tracking and fetching metrics (Metroids) from AWS DynamoDB.
JavaScript
3
star
38

wilks

A Golang implementation of the Wilks Formula for comparing powerlifters across gender and weight class.
Go
3
star
39

whatsthecodeforthat.com

๐Ÿ’ปReference snippets for common tasks in various programming languages.
HTML
3
star
40

hows-the-market

๐Ÿ“ˆ Checking in on the market from your command line.
Go
3
star
41

readme

A command-line tool to fetch and display a projects README.
Go
2
star
42

unity-shader-graph-sprite-effects

C#
2
star
43

DartCalculator

A basic calculator built using Dart
Dart
2
star
44

go-yf

A small wrapper around the Yahoo Finance v8 API written in Go.
Go
2
star
45

GSONVolleyTutorial

Java
2
star
46

btn

Objective-C
1
star
47

unity2d-custom-gravity

Custom Global Gravity in Unity
C#
1
star
48

udacity-ml-engineer-nanodegree

Jupyter Notebook
1
star
49

linguist

A command-line tool to practise translating sentences
Go
1
star
50

kurz

Go
1
star
51

make

Various Makefile Templates
Makefile
1
star