Skip to content

Commit

Permalink
chore: change event payload to json raw (#1535)
Browse files Browse the repository at this point in the history
Signed-off-by: Firas Qutishat <[email protected]>
  • Loading branch information
fqutishat authored Nov 22, 2023
1 parent 1f94a3e commit af4b18c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/event/spi/spi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package spi

import (
"encoding/json"
"time"

utiltime "github.com/trustbloc/did-go/doc/util/time"
Expand Down Expand Up @@ -50,7 +51,7 @@ const (
)

// Payload defines payload.
type Payload []byte
type Payload json.RawMessage

// Event defines event.
type Event struct {
Expand All @@ -73,7 +74,7 @@ type Event struct {
DataContentType string `json:"datacontenttype,omitempty"`

// Data defines message(optional).
Data []byte `json:"data,omitempty"`
Data json.RawMessage `json:"data,omitempty"`

// TransactionID defines transaction ID(optional).
TransactionID string `json:"txnid,omitempty"`
Expand Down Expand Up @@ -108,7 +109,7 @@ func (m *Event) Copy() *Event {
func NewEventWithPayload(uuid string, source string, eventType EventType, payload Payload) *Event {
event := NewEvent(uuid, source, eventType)

event.Data = payload
event.Data = json.RawMessage(payload)

// vcs components always use json
event.DataContentType = "application/json"
Expand Down
6 changes: 5 additions & 1 deletion pkg/event/spi/spi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package spi

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -16,7 +17,10 @@ func TestEvent(t *testing.T) {
event := NewEvent("id", "source", "type")
require.NotNil(t, event)

eventWithPayload := NewEventWithPayload("id", "source", "type", Payload("{}"))
payload, err := json.Marshal(map[string]interface{}{"k1": "v1"})
require.NoError(t, err)

eventWithPayload := NewEventWithPayload("id", "source", "type", payload)
require.NotNil(t, eventWithPayload)

eventCopy := event.Copy()
Expand Down

0 comments on commit af4b18c

Please sign in to comment.