From d05e371da3d2fbdee9701b247c1e802e9bf7cf0b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 28 Nov 2024 18:02:53 +0100 Subject: [PATCH] go: Add convenient construction of rawPayload messages --- go/message.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/go/message.go b/go/message.go index 3beee2164..114878106 100644 --- a/go/message.go +++ b/go/message.go @@ -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 +}