|
@@ -11,6 +11,15 @@ const (
|
|
|
DataContentTypeJson = "application/json"
|
|
|
)
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func NewCloudEvent(eventID string, eventType string, source string, dataContentType string, data []byte) *CloudEvent {
|
|
|
return &CloudEvent{
|
|
|
SpecVersion: "v1.0",
|
|
@@ -23,6 +32,15 @@ func NewCloudEvent(eventID string, eventType string, source string, dataContentT
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func NewCloudEventJson(eventID string, eventType string, source string, obj any) (*CloudEvent, error) {
|
|
|
dataJsonBytes, err := json.Marshal(obj)
|
|
|
if err != nil {
|
|
@@ -40,6 +58,12 @@ func NewCloudEventJson(eventID string, eventType string, source string, obj any)
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func UnmarshalJsonCloudEvent(cloudEventJsonBytes []byte) (*CloudEvent, error) {
|
|
|
event := new(CloudEvent)
|
|
|
err := json.Unmarshal(cloudEventJsonBytes, event)
|
|
@@ -60,6 +84,11 @@ type CloudEvent struct {
|
|
|
Data []byte `json:"data"`
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
func (event *CloudEvent) MarshalJson() ([]byte, error) {
|
|
|
if strutils.IsStringEmpty(event.SpecVersion) {
|
|
|
return nil, errors.New("没有传递事件规范版本")
|