-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmms.go
84 lines (67 loc) · 1.84 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
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"log"
"time"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/middleware"
_ "github.com/lib/pq"
"github.com/steveoc64/godev/echocors"
"github.com/facebookgo/grace/gracehttp"
)
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)
}
// Define all the Routes
e = echo.New()
// e.Group("html/*", middleware.Static("build/html"))
// e.Group("img/*", middleware.Static("build/img"))
// e.Group("fonts/*", middleware.Static("build/fonts"))
// e.Group("css/*", middleware.Static("build/css"))
// e.Group("js/*", middleware.Static("build/js"))
// e.Use(middleware.Static("build"))
// e.Index("./build/index.html")
// e.ServeDir("/", "./build")
_initRoutes()
e.Static("/", "build")
// e.File("/", "build/index.html")
// e.Use(fasthttp.WrapHandler(middleware.Logger()))
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Gzip())
if Config.Debug {
e.SetDebug(true)
}
echocors.Init(e, Config.Debug)
// 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)
}
std := standard.New(fmt.Sprintf(":%d", Config.WebPort))
std.SetHandler(e)
gracehttp.Serve(std.Server)
}
func pinger() {
ticker := time.NewTicker(time.Second * 50) // just under the 1 min mark for nginx default timeouts
for range ticker.C {
pingSockets()
}
}