-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
54 lines (43 loc) · 1.07 KB
/
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
package main
import (
"log"
"net/http"
"github.com/alinowrouzii/service-health-check/models"
"github.com/alinowrouzii/service-health-check/routers"
"github.com/alinowrouzii/service-health-check/runner"
"github.com/alinowrouzii/service-health-check/token"
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/mux"
"gorm.io/gorm"
)
type App struct {
Router *mux.Router
DB *gorm.DB
jwt *token.JWTMaker
runner *runner.Runner
}
func (a *App) connectDB(user, password, dbName string) {
}
func (a *App) Initialize(user, password, dbname, secretKey string, runnerInterval int) {
dbConn, err := models.InitModels()
if err != nil {
log.Fatal(err)
}
a.DB = dbConn
a.jwt, err = token.NewJWTMaker(secretKey, a.DB)
if err != nil {
log.Fatal(err)
}
router := routers.InitRouter(a.DB, a.jwt)
a.Router = router
runner := &runner.Runner{
DB: dbConn,
RunnerIntervalMs: runnerInterval,
}
a.runner = runner
}
func (a *App) Run(addr string) {
log.Println("starting on", addr)
// a.runner.Run()
log.Fatal(http.ListenAndServe(addr, a.Router))
}