-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathservice.go
137 lines (121 loc) · 2.63 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package hyper
import (
"os"
"os/signal"
"syscall"
"github.com/vaniila/hyper/cache"
"github.com/vaniila/hyper/dataloader"
"github.com/vaniila/hyper/engine"
"github.com/vaniila/hyper/gws"
"github.com/vaniila/hyper/logger"
"github.com/vaniila/hyper/message"
"github.com/vaniila/hyper/router"
"github.com/vaniila/hyper/sync"
"github.com/vaniila/hyper/websocket"
)
// Hyper service
type Hyper struct {
id string
addr string
logger logger.Service
cache cache.Service
message message.Service
dataloader dataloader.Service
router router.Service
engine engine.Service
sync sync.Service
gws gws.Service
websocket websocket.Service
}
func (v *Hyper) start() error {
if err := v.logger.Start(); err != nil {
return err
}
if err := v.cache.Start(); err != nil {
return err
}
if err := v.message.Start(); err != nil {
return err
}
if err := v.dataloader.Start(); err != nil {
return err
}
if err := v.router.Start(); err != nil {
return err
}
if err := v.sync.Start(); err != nil {
return err
}
if err := v.gws.Start(); err != nil {
return err
}
if err := v.websocket.Start(); err != nil {
return err
}
if err := v.engine.Start(); err != nil {
return err
}
return nil
}
// Stop hyper server
func (v *Hyper) stop() error {
if err := v.engine.Stop(); err != nil {
return err
}
if err := v.websocket.Stop(); err != nil {
return err
}
if err := v.gws.Stop(); err != nil {
return err
}
if err := v.sync.Stop(); err != nil {
return err
}
if err := v.router.Stop(); err != nil {
return err
}
if err := v.cache.Stop(); err != nil {
return err
}
if err := v.message.Stop(); err != nil {
return err
}
if err := v.dataloader.Stop(); err != nil {
return err
}
if err := v.logger.Stop(); err != nil {
return err
}
return nil
}
// Run hyper server
func (v *Hyper) Run() error {
if err := v.start(); err != nil {
return err
}
v.logger.Info("Server running on %s", logger.NewField("address", v.addr))
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
v.logger.Info("Received signal %s", logger.NewField("signal", <-ch))
return v.stop()
}
// Logger returns logger service
func (v *Hyper) Logger() logger.Service {
return v.logger
}
// Sync returns sync service
func (v *Hyper) Sync() sync.Service {
return v.sync
}
// Gws returns graphql subscription service
func (v *Hyper) Gws() gws.Service {
return v.gws
}
// Router returns router service
func (v *Hyper) Router() router.Service {
return v.router
}
// String returns hyper server in string
func (v *Hyper) String() string {
return "Hyper::Server"
}