-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.go
104 lines (77 loc) · 1.87 KB
/
print.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package resource
import (
"fmt"
"log"
"reflect"
"strings"
)
func printResource(r *Resource, lvl int) {
fmt.Printf("%-16s %-20s %-5v ",
strings.Repeat("| ", lvl)+"|-["+r.Name+"]",
r.Value.Type(), r.isSlice())
if len(r.Tag) > 0 {
fmt.Printf("tag: '%s' ", r.Tag)
}
if r.isSlice() {
fmt.Printf("slice: %s ", r.SliceValue.Type())
}
for _, e := range r.Extends {
fmt.Printf("extends: %s ", e.Value.Type())
}
fmt.Println()
for _, c := range r.Children {
printResource(c, lvl+1)
}
}
func printRoute(r *Route, lvl int) {
fmt.Printf("%s", strings.Repeat("| ", lvl)+"|-/"+r.URI)
if r.IsSlice {
fmt.Printf(" *is slice*")
}
fmt.Println()
for _, h := range r.SliceHandlers {
printHandler(h, true, lvl+1)
}
for _, h := range r.Handlers {
printHandler(h, false, lvl+1)
}
for _, c := range r.Children {
printRoute(c, lvl+1)
}
}
func printHandler(h *Handler, isSlice bool, lvl int) {
fmt.Printf("%s ", strings.Repeat("| ", lvl)+"| -")
if isSlice {
fmt.Printf("[] ")
}
fmt.Println(h.Name + "() Dependencies:")
for t, d := range h.Dependencies {
printDependency(t, d, lvl+1)
}
}
func printDependency(t reflect.Type, d *Dependency, lvl int) {
fmt.Printf("%s %-24s as %-24s", strings.Repeat("| ", lvl)+"-", t, d.Value.Type())
if d.Method != nil {
fmt.Printf(" Init Input:")
} else {
fmt.Printf(" Desn't have Init method")
}
for _, input := range d.Method.Inputs {
fmt.Printf(" %-24s", input)
}
fmt.Println()
}
// Print the Resource the stack,
// marking some resource within the stack
// It is used to alert user for circular dependency
// in the resource relationships
func printResourceStack(resource, mark *Resource) {
if resource.Parent != nil {
printResourceStack(resource.Parent, mark)
}
if resource.isEqual(mark) {
log.Printf("*** -> %s\n", resource.String())
} else {
log.Printf(" -> %s\n", resource.String())
}
}