forked from davidschlachter/embedded-struct-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph.go
38 lines (33 loc) · 717 Bytes
/
graph.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"strings"
)
func buildDOTFile(rankdir string) string {
g := []byte{}
g = append(g, fmt.Sprintf(`
digraph {
rankdir="%s"
`, rankdir)...)
for _, s := range structsList {
if len(s.Embeds) == 0 {
continue
}
g = append(g, getFullStructName(s.Name, s.Package)+" -> { "...)
for e := range s.Embeds {
if IsExcludePkg(e, s.Package) {
continue
}
g = append(g, getFullStructName(e, s.Package)+" "...)
}
g = append(g, "};\n"...)
}
g = append(g, "}"...)
return string(g)
}
func getFullStructName(s string, pkg string) string {
if strings.Contains(s, ".") { // struct name includes package name
return "\"" + s + "\""
}
return "\"" + pkg + "." + s + "\""
}