我正在获取以下写的golang客户端脚本的以下消息响应,以便将信息发送到Amazon SNS:
消息回复:
{\"recipient\":\"test20@test.com\",\"template\":\"welcome_email_v1\",\"type\":\"email\",\"source\":\"noreply@sender.co\",\"user\":{\"first_name\":\"\\\"tester\\\"\",\"last_name\":\"\\\"M\\\"\"}}"
作为上述消息响应的一部分,我不太确定作为user
和first_name
的嵌套last_name
哈希的一部分的多个反斜杠是否正常。如果我缺少某些东西,那么对此有更多经验的人可以抛出一些亮点吗?
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
}
谢谢。
答案 0 :(得分:0)
我在我的请求终点遇到了SNS客户端服务的错误。
我必须传递first_name = tester和last_name = M而不是将它们作为first_name =" tester"和last_name =" M"。