fix: func invoke unmarshals json before setting it in the event (#2256)

Signed-off-by: Calum Murray <cmurray@redhat.com>
This commit is contained in:
Calum Murray 2024-03-29 05:55:40 -04:00 committed by GitHub
parent 87a027338e
commit 701e258acf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package functions
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
@ -152,7 +153,17 @@ func sendEvent(ctx context.Context, route string, m InvokeMessage, t http.RoundT
event.SetID(m.ID)
event.SetSource(m.Source)
event.SetType(m.Type)
if err = event.SetData(m.ContentType, m.Data); err != nil {
if m.ContentType == "application/json" {
var d interface{}
err = json.Unmarshal([]byte(m.Data), &d)
if err != nil {
return
}
err = event.SetData(m.ContentType, d)
if err != nil {
return
}
} else if err = event.SetData(m.ContentType, m.Data); err != nil {
return
}