forked from rcalvs/deed-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
77 lines (70 loc) · 1.9 KB
/
Copy pathapp.go
File metadata and controls
77 lines (70 loc) · 1.9 KB
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
package main
import (
"context"
)
// App struct
type App struct {
ctx context.Context
stockService *StockService
notesService *NotesService
deedsService *DeedsService
updateService *UpdateService
logsService *LogsService
husbandryService *HusbandryService
husbandryBindings *HusbandryBindings
}
// NewApp cria uma nova instância da aplicação
// husbandryService pode ser nil quando Husbandry está desabilitado
func NewApp(stockService *StockService, notesService *NotesService, deedsService *DeedsService, updateService *UpdateService, logsService *LogsService, husbandryService *HusbandryService) *App {
app := &App{
stockService: stockService,
notesService: notesService,
deedsService: deedsService,
updateService: updateService,
logsService: logsService,
husbandryService: husbandryService,
}
if husbandryService != nil {
app.husbandryBindings = NewHusbandryBindings(husbandryService)
}
return app
}
// startup é chamado quando a aplicação inicia
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
// Inicializar banco de dados
if err := a.stockService.Initialize(); err != nil {
panic(err)
}
if err := a.notesService.Initialize(); err != nil {
panic(err)
}
if err := a.deedsService.Initialize(); err != nil {
panic(err)
}
// HUSBANDRY DESABILITADO
if a.husbandryService != nil {
if err := a.husbandryService.Initialize(); err != nil {
panic(err)
}
}
}
// shutdown é chamado quando a aplicação fecha
func (a *App) shutdown(ctx context.Context) {
// Fechar conexão com banco de dados
if err := a.stockService.Close(); err != nil {
panic(err)
}
if err := a.notesService.Close(); err != nil {
panic(err)
}
if err := a.deedsService.Close(); err != nil {
panic(err)
}
// HUSBANDRY DESABILITADO
if a.husbandryService != nil {
if err := a.husbandryService.Close(); err != nil {
panic(err)
}
}
}