OpenFunction / functions-framework-go

Go functions framework for OpenFunction
18 stars 20 forks source link

update cloud event input data to json format #53

Closed lizzzcai closed 2 years ago

lizzzcai commented 2 years ago

followup PR of https://github.com/OpenFunction/functions-framework-go/pull/52 to fix the tests for binary and structured cloud event format.

For cloud event input, data prefer to be in JSON format and unmarshal it in the user code, so that the result will be consistent for both binary and structured format.

binary format:

❯ curl -X POST "http://localhost:8080/bar/openfunction" \
  -H "Ce-Specversion: 1.0" \
  -H "Ce-Type: dev.knative.samples.helloworld" \
  -H "Ce-Source: dev.knative.samples/helloworldsource" \
  -H "Ce-Subject: 123" \
  -H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
  -H "Content-Type: application/json" \
  -d 'hello'
{"hello":"openfunction"}%

structured format:

❯ curl -X POST "http://localhost:8080/bar/openfunction" \
   -H "Content-Type: application/cloudevents+json" \
   -d '{"specversion":"1.0","type":"dev.knative.samples.helloworld","source":"dev.knative.samples/helloworldsource","id":"536808d3-88be-4077-9d7a-a3f162705f79","data":"hello"}'
{"\"hello\"":"openfunction"}% 

you can see there are \" in the data.

lizzzcai commented 2 years ago

@benjaminhuo , the PR is green. I will add examples to the samples repo later this week.

benjaminhuo commented 2 years ago

@benjaminhuo , the PR is green. I will add examples to the samples repo later this week.

That's great, we do need examples in the samples repo.