/
service.go
38 lines (33 loc) · 843 Bytes
/
service.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
package svc
import (
"ftm-gas-monetization/internal/logger"
"ftm-gas-monetization/internal/repository"
)
// serviceHandler represents a service run by the Manager.
type serviceHandler interface {
// init initializes the service
init()
// run executes the service
run()
// close terminates the service
close()
// name provides a name of the service
name() string
}
// service implements general base for services implementing svc interface.
type service struct {
repo *repository.Repository
log *logger.AppLogger
mgr *Manager
sigStop chan struct{}
}
// init prepares the service stop signal channel.
func (s *service) init() {
s.sigStop = make(chan struct{})
}
// close terminates the service by sending the stop signal down the channel.
func (s *service) close() {
if s.sigStop != nil {
close(s.sigStop)
}
}