diff options
-rw-r--r-- | internal/api/handlers.go | 10 | ||||
-rw-r--r-- | main.go | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go index 5a31fa3..2cc2188 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -90,7 +90,7 @@ func CreateLoginHandler(logs *[LogLength]string, n *int, toLogParser chan string var status statusData -func init() { +func InitializeAPI(logs *[LogLength]string, n *int, toLogParser chan string) { // Backfill status // status.overallStatus = overallStatus{ @@ -191,7 +191,7 @@ func init() { runChance(0.5, func() { serviceStatus = StatusDegraded }) - status.incidents = append(status.incidents, incident{ + newIncident := incident{ Id: fmt.Sprintf("%d", incidentId), Title: allIncidentTitles[i], Description: allIncidentDescriptions[i], @@ -199,8 +199,12 @@ func init() { Severity: severity, StartTime: time.Now().UTC(), AffectedServices: []string{}, - }) + } + status.incidents = append(status.incidents, newIncident) incidentId++ + + jsonData, _ := json.Marshal(newIncident) + addRotLog(logs, n, toLogParser, fmt.Sprintf(`{"incidentEvent": %s}`, string(jsonData))) }) status.overallStatus.ActiveIncidents = len(status.incidents) } @@ -36,6 +36,8 @@ func main() { go parser(toLogParser, &king) + api.InitializeAPI(&logs, &n, toLogParser) + http.HandleFunc("/", api.CreateFilesHandler(&logs, &n, toLogParser)) http.HandleFunc("/logs", api.CreateGetLogs(&logs)) http.HandleFunc("/api/v1/logs", api.CreateGetLogs(&logs)) |