/
config.go
93 lines (79 loc) · 1.76 KB
/
config.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
package container
import (
"fmt"
"strings"
)
//Tree of dependency nodes
type Tree []Node
//Event about registration of a specific service
type Event struct {
Name string
Service string
}
func (e Event) String() string {
return fmt.Sprintf(
"{Name: %s; Service: %s;}",
e.Name,
e.Service,
)
}
//IsEmpty checks if Event node contains any data
func (e Event) IsEmpty() bool {
return e.Name == "" && e.Service == ""
}
//Services list of dependencies
type Services []string
func (ss Services) String() string {
return "[" + strings.Join(ss, ";") + "]"
}
//Observer is a service which is interested other services under a certain event
type Observer struct {
Event string
Name string
Callback interface{}
}
//ParametersProvider gives container parameters
type ParametersProvider interface {
GetItems() map[string]interface{}
}
func (o Observer) String() string {
return fmt.Sprintf(
"{Name: %s; Event: %s;}",
o.Name,
o.Event,
)
}
//IsEmpty checks if Observer node contains any data
func (o Observer) IsEmpty() bool {
return o.Name == "" && o.Event == "" && o.Callback == nil
}
//Node of a dependency
type Node struct {
ID string
Constr Constructor
NewFunc interface{}
ServiceNames Services
Ev Event
Ob Observer
Parameters map[string]interface{}
ParamProvider ParametersProvider
GarbageFunc GarbageCollectorFunc
}
func (n Node) String() string {
return fmt.Sprintf(
"Node: {ID: %s; ServiceNames: %s; Event: %s; Observer: %s}",
n.ID,
n.ServiceNames,
n.Ev,
n.Ob,
)
}
//ServiceExists checks if the provided name was already registered for a service
func (t Tree) ServiceExists(serviceID string) bool {
for _, node := range t {
if node.ID == serviceID {
return true
}
}
return false
}