Skip to content

Commit

Permalink
go: Add convenient construction of rawPayload messages
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Nov 28, 2024
1 parent 152134b commit d05e371
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions go/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,29 @@ func (m *Message) ExpungeContent(ctx context.Context, appId string, msgId string
res, err := req.Execute()
return wrapError(err, res)
}

// Instantiates a new MessageIn object with a pre-serialized payload.
//
// The payload is not normalized on the server (usually whitespace outside
// of string literals, unnecessarily escaped characters in string and such
// are fixed up by the server), and is not even required to be JSON.
//
// The last parameter can be used to change the `content-type` header to send,
// overriding the default of `application/json`.
//
// See the class documentation for details about the other parameters.
func NewMessageInRaw(eventType string, payload string, contentType openapi.NullableString) *MessageIn {
msgIn := openapi.NewMessageIn(eventType, make(map[string]interface{}))

transformationsParams := map[string]interface{}{
"rawPayload": payload,
}
if contentType.IsSet() {
transformationsParams["headers"] = map[string]string{
"content-type": *contentType.Get(),
}
}
msgIn.SetTransformationsParams(transformationsParams)

return msgIn
}

0 comments on commit d05e371

Please sign in to comment.