{"id":13612921,"url":"https://github.com/KyleBanks/depth","last_synced_at":"2025-04-13T15:32:08.089Z","repository":{"id":41342328,"uuid":"83904252","full_name":"KyleBanks/depth","owner":"KyleBanks","description":"Visualize Go Dependency Trees","archived":false,"fork":false,"pushed_at":"2022-02-08T04:10:36.000Z","size":41,"stargazers_count":950,"open_issues_count":9,"forks_count":65,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-12-06T19:09:54.601Z","etag":null,"topics":["command-line-tool","dependency-tree","go","visualizer"],"latest_commit_sha":null,"homepage":"https://kylewbanks.com/blog/visualize-golang-dependency-trees-with-depth","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KyleBanks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-04T15:42:23.000Z","updated_at":"2024-11-27T19:15:16.000Z","dependencies_parsed_at":"2022-09-02T04:11:24.031Z","dependency_job_id":null,"html_url":"https://github.com/KyleBanks/depth","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleBanks%2Fdepth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleBanks%2Fdepth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleBanks%2Fdepth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleBanks%2Fdepth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KyleBanks","download_url":"https://codeload.github.com/KyleBanks/depth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248735825,"owners_count":21153475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line-tool","dependency-tree","go","visualizer"],"created_at":"2024-08-01T20:00:36.556Z","updated_at":"2025-04-13T15:32:07.789Z","avatar_url":"https://github.com/KyleBanks.png","language":"Go","readme":"# depth \n\n[![GoDoc](https://godoc.org/github.com/KyleBanks/depth?status.svg)](https://godoc.org/github.com/KyleBanks/depth)\u0026nbsp; \n[![Build Status](https://travis-ci.org/KyleBanks/depth.svg?branch=master)](https://travis-ci.org/KyleBanks/depth)\u0026nbsp;\n[![Go Report Card](https://goreportcard.com/badge/github.com/KyleBanks/depth)](https://goreportcard.com/report/github.com/KyleBanks/depth)\u0026nbsp;\n[![Coverage Status](https://coveralls.io/repos/github/KyleBanks/depth/badge.svg?branch=master)](https://coveralls.io/github/KyleBanks/depth?branch=master)\n\n`depth` is tool to retrieve and visualize Go source code dependency trees.\n\n## Install\n\nDownload the appropriate binary for your platform from the [Releases](https://github.com/KyleBanks/depth/releases) page, or:\n\n```sh\ngo get github.com/KyleBanks/depth/cmd/depth\n```\n\n## Usage\n\n`depth` can be used as a standalone command-line application, or as a package within your own project.\n\n### Command-Line\n\nSimply execute `depth` with one or more package names to visualize. You can use the fully qualified import path of the package, like so:\n\n```sh\n$ depth github.com/KyleBanks/depth/cmd/depth\ngithub.com/KyleBanks/depth/cmd/depth\n  ├ encoding/json\n  ├ flag\n  ├ fmt\n  ├ io\n  ├ log\n  ├ os\n  ├ strings\n  └ github.com/KyleBanks/depth\n    ├ fmt\n    ├ go/build\n    ├ path\n    ├ sort\n    └ strings\n12 dependencies (11 internal, 1 external, 0 testing).\n```\n\nOr you can use a relative path, for example:\n\n```sh\n$ depth .\n$ depth ./cmd/depth\n$ depth ../\n```\n\nYou can also use `depth` on the Go standard library:\n\n```sh\n$ depth strings\nstrings\n  ├ errors\n  ├ internal/bytealg\n  ├ io\n  ├ sync\n  ├ unicode\n  ├ unicode/utf8\n  └ unsafe\n7 dependencies (7 internal, 0 external, 0 testing).\n```\n\nVisualizing multiple packages at a time is supported by simply naming the packages you'd like to visualize:\n\n```sh\n$ depth strings github.com/KyleBanks/depth \nstrings\n  ├ errors\n  ├ internal/bytealg\n  ├ io\n  ├ sync\n  ├ unicode\n  ├ unicode/utf8\n  └ unsafe\n7 dependencies (7 internal, 0 external, 0 testing).\ngithub.com/KyleBanks/depth\n  ├ bytes\n  ├ errors\n  ├ go/build\n  ├ os\n  ├ path\n  ├ sort\n  └ strings\n7 dependencies (7 internal, 0 external, 0 testing).\n```\n\n#### `-internal`\n\nBy 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:\n\n```sh\n$ depth -internal strings\nstrings\n  ├ errors\n  │ └ internal/reflectlite\n  │   ├ internal/unsafeheader\n  │   │ └ unsafe\n  │   ├ runtime\n  │   │ ├ internal/abi\n  │   │ │ └ unsafe\n  │   │ ├ internal/bytealg\n  │   │ │ ├ internal/cpu\n  │   │ │ └ unsafe\n  │   │ ├ internal/cpu\n  │   │ ├ internal/goexperiment\n  │   │ ├ runtime/internal/atomic\n  │   │ │ └ unsafe\n  │   │ ├ runtime/internal/math\n  │   │ │ └ runtime/internal/sys\n  │   │ ├ runtime/internal/sys\n  │   │ └ unsafe\n  │   └ unsafe\n  ├ internal/bytealg\n  ├ io\n  │ ├ errors\n  │ └ sync\n  │   ├ internal/race\n  │   │ └ unsafe\n  │   ├ runtime\n  │   ├ sync/atomic\n  │   │ └ unsafe\n  │   └ unsafe\n  ├ sync\n  ├ unicode\n  ├ unicode/utf8\n  └ unsafe\n18 dependencies (18 internal, 0 external, 0 testing).\n```\n\n#### `-max` \n\nThe `-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:\n\n```\n$ depth -max 1 github.com/KyleBanks/depth/cmd/depth\ngithub.com/KyleBanks/depth/cmd/depth\n  ├ encoding/json\n  ├ flag\n  ├ fmt\n  ├ io\n  ├ log\n  ├ os\n  ├ strings\n  └ github.com/KyleBanks/depth\n7 dependencies (6 internal, 1 external, 0 testing).\n```\n\nThe `-max` flag is particularly useful in conjunction with the `-internal` flag which can lead to very deep dependency trees.\n\n#### `-test`\n\nBy default, `depth` ignores dependencies that are only required for testing. However, you can view test dependencies using the `-test` flag:\n\n```sh\n$ depth -test strings\nstrings\n  ├ bytes\n  ├ errors\n  ├ fmt\n  ├ internal/bytealg\n  ├ internal/testenv\n  ├ io\n  ├ math/rand\n  ├ reflect\n  ├ strconv\n  ├ sync\n  ├ testing\n  ├ unicode\n  ├ unicode/utf8\n  └ unsafe\n14 dependencies (14 internal, 0 external, 7 testing).\n```\n\n#### `-explain target-package`\n\nThe `-explain` flag instructs `depth` to print import chains in which the\n`target-package` is found:\n\n```sh\n$ depth -explain strings github.com/KyleBanks/depth/cmd/depth\ngithub.com/KyleBanks/depth/cmd/depth -\u003e strings\ngithub.com/KyleBanks/depth/cmd/depth -\u003e github.com/KyleBanks/depth -\u003e strings\n```\n\n#### `-json`\n\nThe `-json` flag instructs `depth` to output dependencies in JSON format:\n\n```sh\n$ depth -json github.com/KyleBanks/depth/cmd/depth\n{\n  \"name\": \"github.com/KyleBanks/depth/cmd/depth\",\n  \"deps\": [\n    {\n      \"name\": \"encoding/json\",\n      \"internal\": true,\n      \"deps\": null\n    },\n    ...\n    {\n      \"name\": \"github.com/KyleBanks/depth\",\n      \"internal\": false,\n      \"deps\": [\n        {\n          \"name\": \"go/build\",\n          \"internal\": true,\n          \"deps\": null\n        },\n        ...\n      ]\n    }\n  ]\n}\n```\n\n### Integrating With Your Project\n\nThe `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:\n\n```go\nimport \"github.com/KyleBanks/depth\"\n\nvar t depth.Tree\nerr := t.Resolve(\"strings\")\nif err != nil {\n    log.Fatal(err)\n}\n\n// Output: \"'strings' has 4 dependencies.\"\nlog.Printf(\"'%v' has %v dependencies.\", t.Root.Name, len(t.Root.Deps)) \n```\n\nFor additional customization, simply set the appropriate flags on the `Tree` before resolving:\n\n```go\nimport \"github.com/KyleBanks/depth\"\n\nt := depth.Tree {\n  ResolveInternal: true,\n  ResolveTest: true,\n  MaxDepth: 10,\n}\n\n\nerr := t.Resolve(\"strings\")\n```\n\n## Author\n\n`depth` was developed by [Kyle Banks](https://twitter.com/kylewbanks).\n\n## License\n\n`depth` is available under the [MIT](./LICENSE) license.\n","funding_links":[],"categories":["Go Tools","Go 語言工具","Go","Containers \u0026 Language Extentions \u0026 Linting","Go 工具","Libraries for creating HTTP middlewares","Go工具","Go 语言工具"],"sub_categories":["Routers","路由","For Go","路由器","代码分析"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyleBanks%2Fdepth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKyleBanks%2Fdepth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKyleBanks%2Fdepth/lists"}