refactor: Improve ARR body parsing logic
This commit is contained in:
@@ -20,11 +20,14 @@ var (
|
|||||||
emptyLineRemove = regexp.MustCompile(`(?m)^\s*$`)
|
emptyLineRemove = regexp.MustCompile(`(?m)^\s*$`)
|
||||||
bodyOnly = regexp.MustCompile(`(.|\n)?(ZCZC(.|\n)*)NNNN(.|\n)?$`)
|
bodyOnly = regexp.MustCompile(`(.|\n)?(ZCZC(.|\n)*)NNNN(.|\n)?$`)
|
||||||
originator = regexp.MustCompile(`(?P<originatorDateTime>[0-9]+)\s(?P<originator>[A-Z]+)`)
|
originator = regexp.MustCompile(`(?P<originatorDateTime>[0-9]+)\s(?P<originator>[A-Z]+)`)
|
||||||
navPattern = regexp.MustCompile(`(?m)^NAV\/(?P<nav>.*)$`)
|
navPattern = regexp.MustCompile(`(?m)NAV\/(?P<nav>.*)$`)
|
||||||
remarkPattern = regexp.MustCompile(`(?s)^RMK\/(?P<remark>.*)$`)
|
remarkPattern = regexp.MustCompile(`(?s)RMK\/(?P<remark>.*)`)
|
||||||
selPattern = regexp.MustCompile(`(?m)SEL\/(?P<sel>\w+)`)
|
selPattern = regexp.MustCompile(`(?m)SEL\/(?P<sel>\w+)`)
|
||||||
pbnPattern = regexp.MustCompile(`(?m)PBN\/(?P<pbn>[A-Z0-9]+)`)
|
pbnPattern = regexp.MustCompile(`(?m)PBN\/(?P<pbn>[A-Z0-9]+)`)
|
||||||
otherPatterns = []regexp.Regexp{*navPattern, *remarkPattern, *selPattern, *pbnPattern}
|
eetPattern = regexp.MustCompile(`(?s)(-?EET\/(?P<eet>(?:[A-Z]{4}\d{4}\s*)+))`)
|
||||||
|
performancePattern = regexp.MustCompile(`(?s)-?PER\/(?P<per>\w)`)
|
||||||
|
reroutePattern = regexp.MustCompile(`(?m)RIF\/(?P<rif>.*)[A-Z]{3}\/`)
|
||||||
|
otherPatterns = []regexp.Regexp{*navPattern, *remarkPattern, *selPattern, *pbnPattern, *eetPattern, *performancePattern, *reroutePattern}
|
||||||
)
|
)
|
||||||
|
|
||||||
type BodyParser struct {
|
type BodyParser struct {
|
||||||
@@ -146,10 +149,10 @@ func createBodyData(data map[string]string) (string, interface{}, error) {
|
|||||||
EstimatedArrivalTime: data["estt"],
|
EstimatedArrivalTime: data["estt"],
|
||||||
PBN: otherData["pbn"],
|
PBN: otherData["pbn"],
|
||||||
NavigationEquipment: otherData["nav"],
|
NavigationEquipment: otherData["nav"],
|
||||||
EstimatedElapsedTime: data["eet"],
|
EstimatedElapsedTime: otherData["eet"],
|
||||||
SELCALCode: otherData["sel"],
|
SELCALCode: otherData["sel"],
|
||||||
// PerformanceCategory: data["performance"],
|
PerformanceCategory: otherData["per"],
|
||||||
// RerouteInformation: data["rif"],
|
RerouteInformation: otherData["rif"],
|
||||||
Remarks: otherData["remark"],
|
Remarks: otherData["remark"],
|
||||||
}, nil
|
}, nil
|
||||||
default:
|
default:
|
||||||
@@ -322,7 +325,7 @@ func parseOther(text string) map[string]string {
|
|||||||
for i, name := range re.SubexpNames() {
|
for i, name := range re.SubexpNames() {
|
||||||
// fmt.Printf("index: %d, name: %s\n", i, name)
|
// fmt.Printf("index: %d, name: %s\n", i, name)
|
||||||
if i != 0 && name != "" {
|
if i != 0 && name != "" {
|
||||||
data[name] = match[i]
|
data[name] = strings.TrimSpace(match[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user