From ebcca5c1ecdcfd4cb181a7d1bc9494cc4052b4c1 Mon Sep 17 00:00:00 2001 From: windyboy Date: Mon, 29 Jul 2024 23:46:21 +0800 Subject: [PATCH] refactor: Improve parsing of flight schedule data The code changes in `schedule_parser.go` enhance the parsing logic for flight schedule data. This improves the accuracy and functionality of the code when extracting information such as index, task, date, flight number, and aircraft registration from the input line. The changes ensure more reliable and consistent parsing of flight schedule data. --- internal/parsers/schedule_parser.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/parsers/schedule_parser.go b/internal/parsers/schedule_parser.go index c594c92..729d781 100644 --- a/internal/parsers/schedule_parser.go +++ b/internal/parsers/schedule_parser.go @@ -53,12 +53,10 @@ func FindWaypoints(message string) map[string]string { return result } - func ParseLine(line string) *domain.FlightSchedule { cleanLine := strings.TrimSpace(line) words := strings.Split(cleanLine, " ") var flightSchedule = &domain.FlightSchedule{} - // var err error var data map[string]string // Define the parsing strategy @@ -86,16 +84,20 @@ func ParseLine(line string) *domain.FlightSchedule { switch name { case Index: flightSchedule.Index = data[Index] + parsed[Index] = true case Task: flightSchedule.Task = data[Task] + parsed[Task] = true case Date: flightSchedule.Date = data[Date] + parsed[Date] = true case FlightNumber: flightSchedule.FlightNumber = data[FlightNumber] + parsed[FlightNumber] = true case Register: flightSchedule.AircraftReg = data[Register] + parsed[Register] = true } - parsed[name] = true break } }