refactor: Update config.dev.toml and sub.go for Hasura integration
The code changes in config.dev.toml and sub.go update the configuration and message handling for integrating with Hasura. The config.dev.toml file now includes a new section for Hasura configuration, specifying the endpoint and secret. In sub.go, the UUID field is set to the UUID of the received message, ensuring proper tracking of parsed messages. This refactor enables seamless integration with Hasura and improves the functionality of the code.
This commit is contained in:
@@ -149,19 +149,33 @@ func createBodyData(data map[string]string) (interface{}, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse parses the raw text message and returns a ParsedMessage.
|
||||
// Parse parses the raw text message and returns a ParsedMessage.
|
||||
func Parse(rawText string) (*domain.ParsedMessage, error) {
|
||||
// Parse the header of the message
|
||||
message, err := ParseHeader(rawText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Initialize a new body parser
|
||||
bodyParser := NewBodyParser()
|
||||
|
||||
// Parse the body and footer of the message
|
||||
bodyData, err := bodyParser.Parse(message.BodyAndFooter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Return the message with the parsed header and the error
|
||||
// message.ParsedAt = time.Now()
|
||||
return &message, err
|
||||
}
|
||||
|
||||
// Set the parsed time to the current time
|
||||
message.ParsedAt = time.Now()
|
||||
|
||||
// Assign the parsed body data to the message
|
||||
message.BodyData = bodyData
|
||||
|
||||
// Return the fully parsed message
|
||||
return &message, nil
|
||||
}
|
||||
|
||||
@@ -188,7 +202,7 @@ func ParseHeader(fullMessage string) (domain.ParsedMessage, error) {
|
||||
// fullMessage = strings.TrimSpace(fullMessage)
|
||||
lines := strings.Split(fullMessage, "\n")
|
||||
|
||||
startIndicator, messageID, dateTime, err := parseStartIndicator(lines[0])
|
||||
_, messageID, dateTime, err := parseStartIndicator(lines[0])
|
||||
if err != nil {
|
||||
return domain.ParsedMessage{}, err
|
||||
}
|
||||
@@ -202,7 +216,7 @@ func ParseHeader(fullMessage string) (domain.ParsedMessage, error) {
|
||||
secondaryAddresses, originator, originatorDateTime, bodyAndFooter := parseRemainingLines(lines[2:])
|
||||
|
||||
return domain.ParsedMessage{
|
||||
StartIndicator: startIndicator,
|
||||
// StartIndicator: startIndicator,
|
||||
MessageID: messageID,
|
||||
DateTime: dateTime,
|
||||
PriorityIndicator: priorityIndicator,
|
||||
|
||||
@@ -54,7 +54,7 @@ ALTERNATE ROUTES ADVISED)
|
||||
NNNN`
|
||||
parsedHeader, err := ParseHeader(message)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(parsedHeader.StartIndicator).To(Equal("ZCZC"))
|
||||
// Expect(parsedHeader.StartIndicator).To(Equal("ZCZC"))
|
||||
Expect(parsedHeader.MessageID).To(Equal("TAF6789"))
|
||||
Expect(parsedHeader.DateTime).To(Equal("160530"))
|
||||
Expect(parsedHeader.PriorityIndicator).To(Equal("QU"))
|
||||
@@ -97,7 +97,7 @@ ALL DEPARTURES/ARRIVALS EXPECTED TO BE DELAYED)
|
||||
NNNN`
|
||||
parsedHeader, err := ParseHeader(message)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(parsedHeader.StartIndicator).To(Equal("ZCZC"))
|
||||
// Expect(parsedHeader.StartIndicator).To(Equal("ZCZC"))
|
||||
Expect(parsedHeader.MessageID).To(Equal("NOTAM1122"))
|
||||
Expect(parsedHeader.DateTime).To(Equal("171000"))
|
||||
Expect(parsedHeader.PriorityIndicator).To(Equal("QU"))
|
||||
|
||||
Reference in New Issue
Block a user