I'm getting the below message response for a golang client script that I've written below to send info to Amazon SNS:
Message response:
{\"recipient\":\"test20@test.com\",\"template\":\"welcome_email_v1\",\"type\":\"email\",\"source\":\"noreply@sender.co\",\"user\":{\"first_name\":\"\\\"tester\\\"\",\"last_name\":\"\\\"M\\\"\"}}"
I'm not quite sure if the multiple backward slashes as part of the nested user
hash for first_name
and last_name
as part of the above message response is normal. Can someone with more experience on this please throw some light if I'm missing something?
package services
import (
"encoding/json"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sns"
)
var NotificationType= "email"
func snsNotificationSender(template, recipient, firstName, lastName string, account_id int) (*sns.PublishOutput, error) {
sess := session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{Region: aws.String(os.Getenv("AWS_REGION"))},
Profile: os.Getenv("AWS_SNS_PROFILE"),
}))
svc := sns.New(sess)
var source string = os.Getenv("EMAIL_SOURCE")
type UserInfo struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
type MessageBody struct {
Recipient string `json:"recipient"`
Template string `json:"template"`
NotificationType string `json:"type"`
Source string `json:"source"`
UserInfo `json:"user"`
}
type Message struct {
MessageBody
}
msg := Message{
MessageBody: MessageBody{
Template: template,
Recipient: recipient,
Source: source,
NotificationType: NotificationType,
UserInfo: UserInfo{
FirstName: firstName,
LastName: lastName,
},
},
}
encoded_message, err := json.Marshal(msg)
message := string(encoded_message)
msgParams := &sns.PublishInput{
MessageStructure: aws.String("type: json"),
Message: aws.String(message),
TopicArn: aws.String(os.Getenv("AWS_SNS_ARN_Topic")),
}
msgResp, err := svc.Publish(msgParams)
return msgResp, err
}
Thank you.