-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmms.go
74 lines (60 loc) · 1.42 KB
/
cmms.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 (
"fmt"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
_ "github.com/lib/pq"
"github.com/rs/cors"
"log"
"time"
)
var e *echo.Echo
func main() {
_initSMT()
_loadConfig()
_initJWT()
// Make sure the SMS stuff is all working before we go too far
if Config.SMSOn {
smsbal, smserr := GetSMSBalance()
if smserr != nil {
log.Fatal("Cannot retrieve SMS account info", smserr.Error())
}
log.Println("... Remaining SMS Balance =", smsbal)
}
e = echo.New()
e.Index("./build/index.html")
e.ServeDir("/", "./build")
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Use(mw.Gzip())
if Config.Debug {
e.SetDebug(true)
}
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "DELETE", "PUT", "PATCH"},
AllowCredentials: true,
Debug: Config.Debug,
})
e.Use(c.Handler)
// Define all the Routes
_initRoutes()
// Connect to the DB
_initDB()
// Start the mail server
// _initMailer(fmt.Sprintf("Remaining SMS Balance = %d", smsbal))
_initMailer("mailer")
// Start the socket monitor
go pinger()
// Start the web server
if Config.Debug {
log.Printf("... Starting Web Server on port %d", Config.WebPort)
}
e.Run(fmt.Sprintf(":%d", Config.WebPort))
}
func pinger() {
ticker := time.NewTicker(time.Second * 50) // just under the 1 min mark for nginx default timeouts
for range ticker.C {
pingSockets()
}
}