refactor: Add FlightSchedule.Index field and update parsers

The code changes introduce a new `Index` field in the `FlightSchedule` struct and update the parsers in `aviation_parser.go` and `schedule_parser.go` to handle this field. This addition allows for the extraction and parsing of the `Index` value from flight schedule messages. The changes improve the functionality and accuracy of the code when working with flight schedules.
This commit is contained in:
windyboy
2024-07-29 17:54:52 +08:00
parent bb4faf4d13
commit 8593f6ce9d
4 changed files with 116 additions and 7 deletions
+14 -2
View File
@@ -51,6 +51,7 @@ const (
PerformanceCategory = "per"
RerouteInformation = "rif"
Remarks = "remark"
Index = "idx"
)
var (
@@ -105,8 +106,11 @@ func (bp *BodyParser) Parse() (string, interface{}, error) {
if patternConfig, exists := bp.bodyPatterns[category]; exists && patternConfig.Patterns != nil {
for _, p := range patternConfig.Patterns {
if match := p.Expression.FindStringSubmatch(bp.body); match != nil {
data := extractData(match, p.Expression)
// if match := p.Expression.FindStringSubmatch(bp.body); match != nil {
// data := extractData(match, p.Expression)
// return bp.createBodyData(data)
// }
if data := parse(bp.body, p.Expression); data != nil {
return bp.createBodyData(data)
}
}
@@ -125,6 +129,14 @@ func findCategory(body string) string {
return ""
}
func parse(data string, exp *regexp.Regexp) map[string]string {
match := exp.FindStringSubmatch(data)
if len(match) > 0 {
return extractData(match, exp)
}
return nil
}
func extractData(match []string, re *regexp.Regexp) map[string]string {
data := make(map[string]string)
for i, name := range re.SubexpNames() {