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.
This commit is contained in:
windyboy
2024-07-29 23:46:21 +08:00
parent d053ff8c38
commit ebcca5c1ec
+5 -3
View File
@@ -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
}
}