Files
go-caatsm/internal/domain/cnl.go
windyboy e58fa3bb36 refactor: Add CNL message parsing logic to BodyParser
The code changes in `aviation_parser.go` and `aviation_parser_test.go` add CNL message parsing logic to the `BodyParser` module. This allows for the correct extraction and parsing of CNL messages, including the category, aircraft ID, departure airport, and destination airport. This enhancement improves the overall functionality and accuracy of the code.
2024-07-24 17:15:35 +08:00

30 lines
1.0 KiB
Go

package domain
import "fmt"
// CNL represents the structure of a cancellation (CNL) message
type CNL struct {
Category string `json:"category"` // 电报类别 (Message Category)
AircraftID string `json:"aircraft_id"` // 航空器识别标志 (Aircraft Identification)
DepartureAirport string `json:"departure_airport"` // 起飞机场 (Departure Airport)
DestinationAirport string `json:"destination_airport"` // 到达机场 (Destination Airport)
OtherInfo string `json:"other_info,omitempty"` // 其他信息 (optional) (Other Information)
}
// Validate validates the CNL struct fields
func (c *CNL) Validate() error {
if c.Category == "" {
return fmt.Errorf("telegram category is required")
}
if c.AircraftID == "" {
return fmt.Errorf("aircraft id is required")
}
if c.DepartureAirport == "" {
return fmt.Errorf("departure airport is required")
}
if c.DestinationAirport == "" {
return fmt.Errorf("destination airport is required")
}
return nil
}