Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

depth

> 编程语言
Open source

Visualize Go Dependency Trees

1.1K stars0 likes2 views
WebsiteGitHub

About

Visualize Go Dependency Trees

depth

      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:

bash
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:

bash
$ 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:

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

You can also use depth on the Go standard library:

bash
$ 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:

bash
$ 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:

…

-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:

bash
$ 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:

bash
$ 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:

bash
$ 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:

go
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:

go
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.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gocommand-line-tooldependency-treegovisualizer

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言