cloudevents / sdk-go

Go SDK for CloudEvents
https://cloudevents.github.io/sdk-go/
Apache License 2.0
827 stars 218 forks source link

argo events cannot be Unmarshaled #1081

Open caibirdme opened 3 months ago

caibirdme commented 3 months ago

Here's argo events' data

    {
        "context": {
          "type": "type_of_event_source",
          "specversion": "cloud_events_version",
          "source": "name_of_the_event_source",
          "id": "unique_event_id",
          "time": "event_time",
          "datacontenttype": "type_of_data",
          "subject": "name_of_the_configuration_within_event_source"
        },
        "data": {
          "header": {},
          "body": {},
        }
    }

But when I run

ev := cloudevents.NewEvent()
err := json.Unmarshal(data, &ev)

it reports error. It seems that attributes shouldn't be wrapped into context key?

And here's argo events' doc: https://argoproj.github.io/argo-events/tutorials/02-parameterization/#webhook-event-payload

embano1 commented 3 months ago

@caibirdme this is not a CloudEvent, so won't parse. What is the goal you're trying to achieve? Or is this rather a question that should be asked in the Argo repository?

caibirdme commented 3 months ago

argo-event can convert http request to cloudevent format, which I think could simply use this package to Unmarshal. But it seems like argo's cloudevent is not standard cloudevent...