/
app.go
59 lines (43 loc) · 940 Bytes
/
app.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
package instance
import (
writer "github.com/BrobridgeOrg/gravity-transmitter-postgres/pkg/database/writer"
subscriber "github.com/BrobridgeOrg/gravity-transmitter-postgres/pkg/subscriber/service"
log "github.com/sirupsen/logrus"
)
type AppInstance struct {
done chan bool
writer *writer.Writer
subscriber *subscriber.Subscriber
}
func NewAppInstance() *AppInstance {
a := &AppInstance{
done: make(chan bool),
}
return a
}
func (a *AppInstance) Init() error {
log.Info("Starting application")
// Initializing modules
a.writer = writer.NewWriter()
a.subscriber = subscriber.NewSubscriber(a)
// Initializing Writer
err := a.initWriter()
if err != nil {
return err
}
err = a.subscriber.Init()
if err != nil {
return err
}
return nil
}
func (a *AppInstance) Uninit() {
}
func (a *AppInstance) Run() error {
err := a.subscriber.Run()
if err != nil {
return err
}
<-a.done
return nil
}