/
component.go
43 lines (34 loc) · 951 Bytes
/
component.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
package component
import (
"codnect.io/procyon/app/condition"
"codnect.io/procyon/container"
)
type Component struct {
containerOptions []container.Option
definition *container.Definition
conditions []condition.Condition
}
func New(constructor Constructor, options ...Option) (*Component, error) {
c := &Component{}
for _, opt := range options {
opt.applyOption(c)
}
definition, err := container.MakeDefinition(constructor, c.containerOptions...)
if err != nil {
return nil, err
}
c.definition = definition
return c, nil
}
func (c *Component) Definition() *container.Definition {
return c.definition
}
func (c *Component) ConditionalOn(condition condition.Condition) *Component {
c.conditions = append(c.conditions, condition)
return c
}
func (c *Component) Conditions() []condition.Condition {
conditions := make([]condition.Condition, len(c.conditions))
copy(conditions, c.conditions)
return conditions
}