-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
83 lines (74 loc) · 1.68 KB
/
main.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
package main
import (
"fmt"
"github.com/ninjasphere/app-presets/model"
"github.com/ninjasphere/app-presets/rest"
"github.com/ninjasphere/app-presets/service"
"github.com/ninjasphere/go-ninja/api"
"github.com/ninjasphere/go-ninja/support"
)
var (
info = ninja.LoadModuleInfo("./package.json")
)
//SchedulerApp describes the scheduler application.
type PresetsApp struct {
support.AppSupport
service *service.PresetsService
restServer rest.RestServer
}
// Start is called after the ExportApp call is complete.
func (a *PresetsApp) Start(m *model.Presets) error {
if a.service != nil {
return fmt.Errorf("Service has already been started - the action has been ignored.")
} else {
if m == nil || m.Version == "" {
m = &model.Presets{
Version: Version,
}
}
service := &service.PresetsService{
Model: m,
Save: func(m *model.Presets) {
a.SendEvent("config", m)
},
Conn: a.Conn,
Log: a.Log,
}
service.Save(m)
if err := service.Init(); err != nil {
return err
} else {
a.service = service
a.restServer.Log = a.Log
a.restServer.Presets = service
}
if err := a.restServer.Start(); err != nil {
return err
}
}
return nil
}
// Stop the scheduler module.
func (a *PresetsApp) Stop() error {
tmp := a.service
a.service = nil
if tmp == nil {
return fmt.Errorf("The service is not started - action has been ignored.")
} else {
a.restServer.Stop()
tmp.Destroy()
}
return nil
}
func main() {
app := &PresetsApp{}
err := app.Init(info)
if err != nil {
app.Log.Fatalf("failed to initialize app: %v", err)
}
err = app.Export(app)
if err != nil {
app.Log.Fatalf("failed to export app: %v", err)
}
support.WaitUntilSignal()
}