在消息响应中获取多个反斜杠作为发送到 Amazon SNS 的嵌套信息的一部分 - 我是否遗漏了什么



我收到以下消息响应,用于我在下面编写的用于将信息发送到Amazon SNS:

消息响应:

{"recipient":"test20@test.com","template":"welcome_email_v1","type":"email","source":"noreply@sender.co","user":{"first_name":"\"tester\"","last_name":"\"M\""}}"

我不太确定作为first_name嵌套user哈希的一部分的多个反斜杠和作为上述消息响应一部分的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
}

谢谢。

我在命中SNS客户端服务的请求端点中犯了一个错误。

我必须通过 first_name=tester 和 last_name=M,而不是将它们作为 first_name="测试器" 和 last_name="M"。

相关内容

最新更新