This repository was archived by the owner on Dec 11, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed
pkg/converter/cloudevents Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -26,12 +26,12 @@ import (
2626)
2727
2828type ceBody struct {
29- ID string `json:"id"`
30- Type string `json:"type"`
31- Time string `json:"time"`
32- Source string `json:"source"`
33- Specversion string `json:"specversion"`
34- Data string `json:"data"`
29+ ID string `json:"id"`
30+ Type string `json:"type"`
31+ Time string `json:"time"`
32+ Source string `json:"source"`
33+ Specversion string `json:"specversion"`
34+ Data interface {} `json:"data"`
3535}
3636
3737const contentType = "application/cloudevents+json"
@@ -59,13 +59,21 @@ func (ce *CloudEvent) Convert(data []byte) ([]byte, error) {
5959 return nil , nil
6060 }
6161
62+ var body interface {}
63+ body = string (data )
64+
65+ // try to decode function's response into JSON
66+ if json .Valid (data ) {
67+ body = json .RawMessage (data )
68+ }
69+
6270 b := ceBody {
6371 ID : uuid .NewString (),
6472 Type : ce .EventType ,
6573 Time : time .Now ().Format (time .RFC3339 ),
6674 Source : ce .Source ,
6775 Specversion : "1.0" ,
68- Data : string ( data ) ,
76+ Data : body ,
6977 }
7078 return json .Marshal (b )
7179}
You can’t perform that action at this time.
0 commit comments