Skip to content

Commit

Permalink
Add null check and change time format
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Nisar <[email protected]>
  • Loading branch information
yash-nisar committed Aug 1, 2023
1 parent 96360e2 commit 602c075
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions bindings/azure/storagequeues/storagequeues.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
expirationTime = "expirationTime"
nextVisibleTime = "nextVisibleTime"
popReceipt = "popReceipt"
messageId = "messageId"
messageID = "messageID"
)

type consumer struct {
Expand Down Expand Up @@ -183,16 +183,22 @@ func (d *AzureQueueHelper) Read(ctx context.Context, consumer *consumer) error {
}
}

metadata := make(map[string]string)

metadata[insertionTime] = res.Messages[0].InsertionTime.Format(time.RFC3339)
metadata[expirationTime] = res.Messages[0].ExpirationTime.Format(time.RFC3339)
metadata[nextVisibleTime] = res.Messages[0].TimeNextVisible.Format(time.RFC3339)
metadata[dequeueCount] = strconv.FormatInt(*res.Messages[0].DequeueCount, 10)

if res.Messages[0].MessageID != nil {
metadata[messageID] = *res.Messages[0].MessageID
}
if res.Messages[0].MessageID != nil {
metadata[popReceipt] = *res.Messages[0].PopReceipt
}
_, err = consumer.callback(ctx, &bindings.ReadResponse{
Data: data,
Metadata: map[string]string{
messageId: *res.Messages[0].MessageID,
insertionTime: res.Messages[0].InsertionTime.Format("2006-01-02 15:04:05"),
expirationTime: res.Messages[0].ExpirationTime.Format("2006-01-02 15:04:05"),
popReceipt: *res.Messages[0].PopReceipt,
nextVisibleTime: res.Messages[0].TimeNextVisible.Format("2006-01-02 15:04:05"),
dequeueCount: strconv.FormatInt(*res.Messages[0].DequeueCount, 10),
},
Data: data,
Metadata: metadata,
})
if err != nil {
return err
Expand Down

0 comments on commit 602c075

Please sign in to comment.