Skip to content

Commit

Permalink
fix: func invoke unmarshals json before setting it in the event (#2256)
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 committed Mar 29, 2024
1 parent 87a0273 commit 701e258
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/functions/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package functions
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 701e258

Please sign in to comment.