Popularity
7.1
Declining
Activity
0.0
Stable
868
15
68

Programming language: Go
License: MIT License
Tags: Go Tools    
Latest version: v1.2.1

depth alternatives and similar packages

Based on the "Go Tools" category.
Alternatively, view depth alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of depth or a related project?

Add another 'Go Tools' Package

README

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) license.


*Note that all licence references and agreements mentioned in the depth README section above are relevant to that project's source code only.