/
composite.go
48 lines (38 loc) · 1.09 KB
/
composite.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
package filler
import (
"github.com/artarts36/service-navigator/internal/domain"
"github.com/artarts36/service-navigator/internal/infrastructure/service/datastruct"
"github.com/artarts36/service-navigator/internal/infrastructure/service/monitor"
"github.com/mitchellh/hashstructure"
)
type CompositeFiller struct {
fillers []monitor.Filler
}
func NewCompositeFiller(fillers []monitor.Filler) monitor.Filler {
return &CompositeFiller{
fillers: fillers,
}
}
func (r *CompositeFiller) Fill(service *domain.ServiceStatus, container *datastruct.Container) {
for _, resolver := range r.fillers {
resolver.Fill(service, container)
}
}
type OrFiller struct {
fillers []monitor.Filler
}
func NewOrFiller(fillers []monitor.Filler) monitor.Filler {
return &OrFiller{
fillers: fillers,
}
}
func (r *OrFiller) Fill(service *domain.ServiceStatus, container *datastruct.Container) {
prevHash, _ := hashstructure.Hash(service, nil)
for _, resolver := range r.fillers {
resolver.Fill(service, container)
newHash, _ := hashstructure.Hash(service, nil)
if prevHash != newHash {
return
}
}
}