-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (59 loc) · 1.96 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
package main
import (
"errors"
"log"
"os"
"time"
_ "github.com/docker/go-healthcheck"
health "github.com/docker/go-healthcheck"
"github.com/sirupsen/logrus"
dbclient "patelmaulik.com/maulik/v1/dbclient"
service "patelmaulik.com/maulik/v1/services"
)
var appName = "GoServiceSvc"
var checkFileName = "/tmp/disable"
func main() {
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.Infof("Starting %v\n", appName)
/*
if _, err := os.Create(checkFileName); err != nil {
log.Fatalf("Startup error : Couldn't create check file: %v", checkFileName)
}
*/
d := Initialise()
h := service.AccountHandler{}
h.DBClient = d
health.Register("healthchecker", health.PeriodicChecker(DatabaseCheck(d), time.Second*5))
health.Register("fileChecker", health.PeriodicThresholdChecker(MyFileChecker("/tmp/disable"), time.Second*5, 2))
//health.Register("fileChecker", health.PeriodicChecker(checks.FileChecker("/tmp/disable"), time.Second*5))
// an := negroni.New(negroni.HandlerFunc(mw.HandlerWithNext), negroni.Wrap(ar))
logger := log.New(os.Stderr, "logger: ", log.Lshortfile)
server := service.NewServer()
server.StartWebServer("8080", &h, logger)
}
// DatabaseCheck - check connection
func DatabaseCheck(db *dbclient.DatabaseRepository) health.Checker {
return health.CheckFunc(func() error {
if cnn := db.CheckConection(); cnn == false {
return errors.New("Database connection lost!")
}
return nil
})
}
// MyFileChecker - if the file exists.
func MyFileChecker(f string) health.Checker {
return health.CheckFunc(func() error {
if _, err := os.Stat(f); err == nil {
return errors.New("file exists")
}
return nil
})
}
// Initialise - Seed data
func Initialise() *dbclient.DatabaseRepository {
DatabaseClient := dbclient.DatabaseRepository{}
DatabaseClient.OpenDatabase()
DatabaseClient.SeedDatabase()
return &DatabaseClient // dbclient.IDatabaseRepository(DatabaseClient)
// return &DatabaseClient // dbclient.IDatabaseRepository(DatabaseClient)
}