Last active
August 29, 2015 14:06
-
-
Save gorsuch/49c529010251f35c90f5 to your computer and use it in GitHub Desktop.
publishing to sns in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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