forked from yourheropaul/inj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.go
39 lines (29 loc) · 854 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
39
package inj
import "reflect"
// A Graph object represents an flat tree of application
// dependencies, a count of currently unmet dependencies,
// and a list of encountered errors.
type Graph struct {
nodes nodeMap
UnmetDependencies int
Errors []string
indexes []reflect.Type
datasourceReaders []DatasourceReader
datasourceWriters []DatasourceWriter
}
// Create a new instance of a graph with allocated memory
func NewGraph(providers ...interface{}) (g *Graph) {
g = &Graph{}
g.nodes = make(nodeMap)
g.Errors = make([]string, 0)
g.datasourceReaders = make([]DatasourceReader, 0)
g.datasourceWriters = make([]DatasourceWriter, 0)
g.Provide(providers...)
return
}
// Add a node by reflection type
func (g *Graph) add(typ reflect.Type) (n *graphNode) {
n = newGraphNode()
g.nodes[typ] = n
return
}