forked from maxclaus/go-uptime-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (44 loc) · 1.04 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
package main
import (
"log"
"net/http"
"os"
"github.com/maxcnunes/go-uptime-api/monitor"
dm "github.com/maxcnunes/go-uptime-api/monitor/data"
"github.com/maxcnunes/go-uptime-api/server"
)
var (
db = dm.DB{}
data = dm.DataMonitor{}
job = monitor.Job{}
router = server.Router{}
websocket = server.Websocket{}
)
func main() {
db.Start()
defer db.Close()
data.Start(db)
http.Handle("/", router.Start(&data))
http.HandleFunc("/ws", websocket.Start(&data))
job.Start(&data, getTimeTargetsVerification())
addr := getServiceAddress()
log.Printf("Server running on http://%s", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
func getTimeTargetsVerification() string {
if env := os.Getenv("CHECK_TARGETS_AT_EVERY"); env != "" {
return env
}
return "10m"
}
func getServiceAddress() string {
if env := os.Getenv("PORT_BEHIND_PROXY"); env != "" {
return ":" + env
}
if env := os.Getenv("VIRTUAL_PORT"); env != "" {
return ":" + env
}
return ":3000"
}