Skip to content

Commit

Permalink
Fix parse import modules
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongtrh committed Aug 30, 2021
1 parent 85278e8 commit 8c87953
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# godepviz
Visualize Go dependency in Graphviz DOT format.

Support visualize package from [https://pkg.go.dev](https://pkg.go.dev/)
Visualize Go dependency in Graphviz DOT format.

Support visualize package from [https://pkg.go.dev](https://pkg.go.dev/)

## Installation

Expand All @@ -15,7 +15,8 @@ $ go get github.com/chuongtrh/godepviz
```bash
$ godepviz github.com/gofiber/fiber/v2
```
The output is a graph in [Graphviz](http://graphviz.org/) dot format.

The output is a graph in [Graphviz](http://graphviz.org/) dot format.

```base
digraph G {
Expand Down Expand Up @@ -46,16 +47,23 @@ $ godepviz github.com/gofiber/fiber/v2 | dot -Tpng -o godep.png
```

Export SVG file with a large graph have many nodes of dependencies

```bash
$ godepviz github.com/gofiber/fiber/v2 | dot -Gdpi=0 -T svg -o godep.svg
```

Run from source code

```bash
$ go run main.go go.uber.org/zap | dot -Tpng -o godep.png
```

## Example

- Package `net/http`

![Example net/http](./screenshots/godep.png)


- Package `github.com/labstack/echo/v4`

![Example github.com/labstack/echo/v4](./screenshots/godep1.png)
Expand Down
8 changes: 4 additions & 4 deletions godep/godep.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,21 @@ func fetchImport(pkgImportURL string, isRoot bool) (map[string]string, error) {

docs := root.FindAll("h2", "class", "Imports-heading")
for _, doc := range docs {
text := doc.Text()
text := strings.ToLower(doc.Text())

if strings.Contains(text, "Standard library Imports") {
if strings.Contains(text, "standard library imports") {
temp := doc.FindNextElementSibling()
links := temp.FindAll("a")
for _, link := range links {
imports[link.FullText()] = "standard"
}
} else if strings.Contains(text, "Imports in module") {
} else if strings.Contains(text, "imports in module") {
temp := doc.FindNextElementSibling()
links := temp.FindAll("a")
for _, link := range links {
imports[link.FullText()] = "internal"
}
} else if strings.Contains(text, "Imports") {
} else if strings.Contains(text, "imports") {
temp := doc.FindNextElementSibling()
links := temp.FindAll("a")
for _, link := range links {
Expand Down

0 comments on commit 8c87953

Please sign in to comment.