-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
67 lines (60 loc) · 1.36 KB
/
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
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
package service
import (
"context"
"github.com/LumeWeb/libs5-go/config"
"github.com/LumeWeb/libs5-go/db"
"go.uber.org/zap"
)
type ServicesSetter interface {
SetServices(services Services)
}
type Service interface {
Start(ctx context.Context) error
Stop(ctx context.Context) error
Init(ctx context.Context) error
Logger() *zap.Logger
Config() *config.NodeConfig
Db() db.KVStore
ServicesSetter
}
type Services interface {
P2P() P2PService
Registry() RegistryService
HTTP() HTTPService
Storage() StorageService
All() []Service
Init(ctx context.Context) error
IsStarted() bool
IsStarting() bool
Start(ctx context.Context) error
Stop(ctx context.Context) error
}
type ServiceParams struct {
Logger *zap.Logger
Config *config.NodeConfig
Db db.KVStore
}
type ServiceBase struct {
logger *zap.Logger
config *config.NodeConfig
db db.KVStore
services Services
}
func NewServiceBase(logger *zap.Logger, config *config.NodeConfig, db db.KVStore) ServiceBase {
return ServiceBase{logger: logger, config: config, db: db}
}
func (s *ServiceBase) SetServices(services Services) {
s.services = services
}
func (s *ServiceBase) Services() Services {
return s.services
}
func (s *ServiceBase) Logger() *zap.Logger {
return s.logger
}
func (s *ServiceBase) Config() *config.NodeConfig {
return s.config
}
func (s *ServiceBase) Db() db.KVStore {
return s.db
}