Skip to content

Commit

Permalink
Updating to_event_go so it serializes time correctly
Browse files Browse the repository at this point in the history
Signed-off-by: MaryamTaj <tajm48822@gmail.com>
  • Loading branch information
MaryamTaj authored and duglin committed Oct 31, 2024
1 parent 31930b5 commit ebf4c23
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions v2/binding/to_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"errors"
"fmt"
"io"
"time"

"github.com/cloudevents/sdk-go/v2/binding/format"
"github.com/cloudevents/sdk-go/v2/binding/spec"
Expand Down Expand Up @@ -138,6 +139,16 @@ func (b *messageToEventBuilder) SetAttribute(attribute spec.Attribute, value int
}
return nil
}

// Check if the attribute is 'time' and set it correctly
if attribute.Kind() == spec.Time {
t, ok := value.(time.Time)
if !ok {
return fmt.Errorf("expected time.Time for 'time' attribute, got %T", value)
}
return attribute.Set(b.Context, t)
}

return attribute.Set(b.Context, value)
}

Expand Down

0 comments on commit ebf4c23

Please sign in to comment.