Skip to content

Instantly share code, notes, and snippets.

@gorsuch
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gorsuch/49c529010251f35c90f5 to your computer and use it in GitHub Desktop.
Save gorsuch/49c529010251f35c90f5 to your computer and use it in GitHub Desktop.
publishing to sns in go
package main
import (
"encoding/xml"
"io/ioutil"
"log"
"net/url"
"github.com/bmizerany/aws4"
)
type ErrorResponse struct {
Error struct {
Type string
Code string
Message string
}
RequestId string
}
type PublishResponse struct {
PublishResult struct {
MessageId string
}
ResponseMetadata struct {
RequestId string
}
}
func main() {
v := make(url.Values)
v.Set("Action", "Publish")
v.Set("TopicArn", "REDACTED")
v.Set("Message", "foo")
v.Set("Subject", "test")
res, err := aws4.PostForm("http://sns.us-east-1.amazonaws.com/", v)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
log.Println(res.StatusCode)
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
if res.StatusCode != 200 {
var errorResponse ErrorResponse
err := xml.Unmarshal(body, &errorResponse)
if err != nil {
log.Fatal(err)
}
log.Fatal(errorResponse)
}
var publishResponse PublishResponse
err = xml.Unmarshal(body, &publishResponse)
if err != nil {
log.Fatal(err)
}
log.Print(publishResponse)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment