-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (52 loc) · 1.56 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
package main
import (
"DocPlanner/pingdom-statuspage-integration/statuspage"
"fmt"
"os"
"strconv"
"time"
)
type Response struct {
Status string `json:"status"`
}
func main() {
tickerComponents := time.NewTicker(30 * time.Minute)
defer tickerComponents.Stop()
tickerIncidents := time.NewTicker(30 * time.Second)
defer tickerIncidents.Stop()
componentsStoreChan := make(chan *componentsStore)
incidentStore := &incidentStore{}
secret := getSecret()
statusPageClient := setupStatusPageClient()
go AsyncRefresh(tickerComponents, componentsStoreChan)
go AsyncIncidentCheck(tickerIncidents, statusPageClient, incidentStore)
router := SetupRouter(statusPageClient, secret, componentsStoreChan, incidentStore)
_ = router.Run(":80")
}
func getSecret() string {
secret := os.Getenv("SECRET")
if len(secret) == 0 {
fmt.Println("Environment variable \"SECRET\" not set!")
os.Exit(1)
}
return secret
}
func setupStatusPageClient() *statuspage.Client {
statuspageToken := os.Getenv("STATUSPAGE_TOKEN")
if len(statuspageToken) == 0 {
fmt.Println("Environment variable \"STATUSPAGE_TOKEN\" not set!")
os.Exit(1)
}
statusPageClient := statuspage.NewClient(statuspageToken)
envMaxRetries := os.Getenv("MAX_RETRIES")
if len(envMaxRetries) > 0 {
retries, _ := strconv.Atoi(envMaxRetries)
statusPageClient.MaxRetries = retries
}
envRetryInterval := os.Getenv("RETRY_INTERVAL")
if len(envRetryInterval) > 0 {
interval, _ := strconv.Atoi(envRetryInterval)
statusPageClient.RetryInterval = time.Duration(interval) * time.Second
}
return statusPageClient
}