-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (63 loc) · 1.64 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
package main
import (
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"github.com/shaileshhb/budget-planner-go/budgetplanner"
"github.com/shaileshhb/budget-planner-go/budgetplanner/config"
"github.com/shaileshhb/budget-planner-go/budgetplanner/db"
"github.com/shaileshhb/budget-planner-go/budgetplanner/log"
"github.com/shaileshhb/budget-planner-go/budgetplanner/repository"
"github.com/shaileshhb/budget-planner-go/budgetplanner/security"
"github.com/shaileshhb/budget-planner-go/module"
)
var production = "false"
func main() {
isAppInProduction := false
if production == "true" {
isAppInProduction = true
}
// creates new instance of Logger
log := log.GetLogger()
// creates new instance of Config
envconfig := config.NewConfig(isAppInProduction)
// Create New Instace of DB
db := db.NewDBConnection(log, envconfig)
if db == nil {
log.Fatal("Db connection failed.")
}
defer func() {
sqlDB, err := db.DB()
if err != nil {
log.Fatal(err)
}
sqlDB.Close()
// db.Close()
log.Info("Db closed")
}()
midlware := security.NewAuthentication(db, envconfig)
var wg sync.WaitGroup
var repository = repository.NewGormRepository()
app := budgetplanner.NewApp("Money wisely", db, log, envconfig,
&wg, midlware, isAppInProduction, repository)
module.CreateRouterInstance(app, repository)
module.Configure(app)
err := app.Start()
if err != nil {
log.Fatal(err)
stopApp(app)
}
// Stop Server On System Call or Interrupt.
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
<-ch
stopApp(app)
}
func stopApp(app *budgetplanner.App) {
app.Stop()
app.WG.Wait()
fmt.Println("After wait")
os.Exit(0)
}