-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
53 lines (45 loc) · 1.02 KB
/
resources.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
package resources
import "github.com/devdammit/shekel/pkg/log"
type ResourceService interface {
GetName() string
Start() error
Stop() error
}
type Service struct {
resources []ResourceService
}
func NewService(resources ...ResourceService) *Service {
return &Service{
resources: resources,
}
}
func (s *Service) Start() {
log.Info("starting resources service")
for _, resource := range s.resources {
err := resource.Start()
if err != nil {
log.With(
log.Err(err),
log.String("resource", resource.GetName()),
).Fatal("could not start resource")
}
log.With(
log.String("resource", resource.GetName()),
).Info("resource started")
}
}
func (s *Service) Stop() {
log.Info("stopping resources service")
for _, resource := range s.resources {
err := resource.Stop()
if err != nil {
log.With(
log.Err(err),
log.String("resource", resource.GetName()),
).Fatal("could not stop resource")
}
log.With(
log.String("resource", resource.GetName()),
).Info("resource stopped")
}
}