package main import ( "encoding/csv" "log" "os" ) func getUNMSLogs() UNMSLogResponse { var l UNMSLogResponse log.Println("Get Outages from UNMS") err := UnmsCallAPI("/outages?count=100&page=1&type=outage", &l) if err != nil { log.Fatalln("Error calling Outages API") } return l } func writeOutagesToCSV(l UNMSLogResponse) error { csvFile, err := os.Create("output/outages.csv") if err != nil { return err } writer := csv.NewWriter(csvFile) for _, o := range l.Items { var row []string row = append(row, o.StartTime.Format("02.01.2006 15:04:05")) row = append(row, o.EndTime.Format("02.01.2006 15:04:05")) row = append(row, o.Site.Name) row = append(row, o.Device.DisplayName) writer.Write(row) } writer.Flush() return nil }