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 (
26
26
)
27
27
28
28
type 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"`
35
35
}
36
36
37
37
const contentType = "application/cloudevents+json"
@@ -59,13 +59,21 @@ func (ce *CloudEvent) Convert(data []byte) ([]byte, error) {
59
59
return nil , nil
60
60
}
61
61
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
+
62
70
b := ceBody {
63
71
ID : uuid .NewString (),
64
72
Type : ce .EventType ,
65
73
Time : time .Now ().Format (time .RFC3339 ),
66
74
Source : ce .Source ,
67
75
Specversion : "1.0" ,
68
- Data : string ( data ) ,
76
+ Data : body ,
69
77
}
70
78
return json .Marshal (b )
71
79
}
You can’t perform that action at this time.
0 commit comments