forked from openshift/library-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
73 lines (57 loc) · 1.37 KB
/
resource.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
package resourcegraph
import (
"fmt"
)
type simpleSource struct {
coordinates ResourceCoordinates
note string
nested []Resource
sources []Resource
}
func (r *simpleSource) Coordinates() ResourceCoordinates {
return r.coordinates
}
func (s *simpleSource) Add(resources Resources) Resource {
resources.Add(s)
return s
}
func (s *simpleSource) From(source Resource) Resource {
s.sources = append(s.sources, source)
return s
}
func (s *simpleSource) Note(note string) Resource {
s.note = note
return s
}
func (s *simpleSource) String() string {
return fmt.Sprintf("%v%s", s.coordinates, s.note)
}
func (s *simpleSource) GetNote() string {
return s.note
}
func (s *simpleSource) Sources() []Resource {
return s.sources
}
func (r *simpleSource) Dump(indentDepth int) []string {
lines := []string{}
lines = append(lines, indent(indentDepth, r.String()))
for _, nested := range r.nested {
lines = append(lines, nested.Dump(indentDepth+1)...)
}
return lines
}
func (r *simpleSource) DumpSources(indentDepth int) []string {
lines := []string{}
lines = append(lines, indent(indentDepth, r.String()))
for _, source := range r.sources {
lines = append(lines, source.DumpSources(indentDepth+1)...)
}
return lines
}
func indent(depth int, in string) string {
indent := ""
for i := 0; i < depth; i++ {
indent = indent + " "
}
return indent + in
}