-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (56 loc) · 1.38 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
package main
import (
"encoding/json"
"fmt"
"log"
"time"
"github.com/brennii96/sla-checker/pkg/holidays"
"github.com/brennii96/sla-checker/pkg/slachecker"
)
func main() {
// Fetch holidays concurrently
holidaysCh := make(chan []time.Time)
errorCh := make(chan error)
go func() {
fetchedHolidays, err := holidays.FetchHolidays(2024, "GB")
if err != nil {
errorCh <- err
return
}
holidaysCh <- fetchedHolidays
}()
// Initialize start time, SLA settings, and valid days
startTime := time.Date(2024, time.August, 30, 16, 0, 0, 0, time.UTC)
validDays := []time.Weekday{
time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday,
}
// Create SLA configuration
sla := slachecker.SLA{
StartTime: startTime,
SLALength: 4,
TimeUnit: "hours", // SLA length of 4 hours
BusinessHours: struct {
StartHour int
EndHour int
}{
StartHour: 9,
EndHour: 17,
},
ValidDays: validDays,
}
// Wait for the holidays to be fetched
select {
case err := <-errorCh:
log.Fatalf("Error fetching holidays: %v", err)
case fetchedHolidays := <-holidaysCh:
sla.Holidays = fetchedHolidays
}
// Check SLA with current time
result := sla.CheckSLA(time.Now().UTC())
// Marshal and print JSON result
jsonData, err := json.MarshalIndent(result, "", " ")
if err != nil {
log.Fatalf("Error marshaling JSON: %v", err)
}
fmt.Println(string(jsonData))
}