Switch to using the dep tool and update all the dependencies

This commit is contained in:
Nick Craig-Wood
2017-05-11 15:39:54 +01:00
parent 5135ff73cb
commit 98c2d2c41b
5321 changed files with 4483197 additions and 5918 deletions
File diff suppressed because it is too large Load Diff
+30
View File
@@ -0,0 +1,30 @@
// +build integration
package sqs_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/awstesting/unit"
"github.com/aws/aws-sdk-go/service/sqs"
)
func TestFlattenedTraits(t *testing.T) {
s := sqs.New(unit.Session)
_, err := s.DeleteMessageBatch(&sqs.DeleteMessageBatchInput{
QueueURL: aws.String("QUEUE"),
Entries: []*sqs.DeleteMessageBatchRequestEntry{
{
ID: aws.String("TEST"),
ReceiptHandle: aws.String("RECEIPT"),
},
},
})
assert.Error(t, err)
assert.Equal(t, "InvalidAddress", err.Code())
assert.Equal(t, "The address QUEUE is not valid for this endpoint.", err.Message())
}
+115
View File
@@ -0,0 +1,115 @@
package sqs
import (
"crypto/md5"
"encoding/hex"
"fmt"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
)
var (
errChecksumMissingBody = fmt.Errorf("cannot compute checksum. missing body")
errChecksumMissingMD5 = fmt.Errorf("cannot verify checksum. missing response MD5")
)
func setupChecksumValidation(r *request.Request) {
if aws.BoolValue(r.Config.DisableComputeChecksums) {
return
}
switch r.Operation.Name {
case opSendMessage:
r.Handlers.Unmarshal.PushBack(verifySendMessage)
case opSendMessageBatch:
r.Handlers.Unmarshal.PushBack(verifySendMessageBatch)
case opReceiveMessage:
r.Handlers.Unmarshal.PushBack(verifyReceiveMessage)
}
}
func verifySendMessage(r *request.Request) {
if r.DataFilled() && r.ParamsFilled() {
in := r.Params.(*SendMessageInput)
out := r.Data.(*SendMessageOutput)
err := checksumsMatch(in.MessageBody, out.MD5OfMessageBody)
if err != nil {
setChecksumError(r, err.Error())
}
}
}
func verifySendMessageBatch(r *request.Request) {
if r.DataFilled() && r.ParamsFilled() {
entries := map[string]*SendMessageBatchResultEntry{}
ids := []string{}
out := r.Data.(*SendMessageBatchOutput)
for _, entry := range out.Successful {
entries[*entry.Id] = entry
}
in := r.Params.(*SendMessageBatchInput)
for _, entry := range in.Entries {
if e := entries[*entry.Id]; e != nil {
err := checksumsMatch(entry.MessageBody, e.MD5OfMessageBody)
if err != nil {
ids = append(ids, *e.MessageId)
}
}
}
if len(ids) > 0 {
setChecksumError(r, "invalid messages: %s", strings.Join(ids, ", "))
}
}
}
func verifyReceiveMessage(r *request.Request) {
if r.DataFilled() && r.ParamsFilled() {
ids := []string{}
out := r.Data.(*ReceiveMessageOutput)
for i, msg := range out.Messages {
err := checksumsMatch(msg.Body, msg.MD5OfBody)
if err != nil {
if msg.MessageId == nil {
if r.Config.Logger != nil {
r.Config.Logger.Log(fmt.Sprintf(
"WARN: SQS.ReceiveMessage failed checksum request id: %s, message %d has no message ID.",
r.RequestID, i,
))
}
continue
}
ids = append(ids, *msg.MessageId)
}
}
if len(ids) > 0 {
setChecksumError(r, "invalid messages: %s", strings.Join(ids, ", "))
}
}
}
func checksumsMatch(body, expectedMD5 *string) error {
if body == nil {
return errChecksumMissingBody
} else if expectedMD5 == nil {
return errChecksumMissingMD5
}
msum := md5.Sum([]byte(*body))
sum := hex.EncodeToString(msum[:])
if sum != *expectedMD5 {
return fmt.Errorf("expected MD5 checksum '%s', got '%s'", *expectedMD5, sum)
}
return nil
}
func setChecksumError(r *request.Request, format string, args ...interface{}) {
r.Retryable = aws.Bool(true)
r.Error = awserr.New("InvalidChecksum", fmt.Sprintf(format, args...), nil)
}
+208
View File
@@ -0,0 +1,208 @@
package sqs_test
import (
"bytes"
"io/ioutil"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/awstesting/unit"
"github.com/aws/aws-sdk-go/service/sqs"
)
var svc = func() *sqs.SQS {
s := sqs.New(unit.Session, &aws.Config{
DisableParamValidation: aws.Bool(true),
})
s.Handlers.Send.Clear()
return s
}()
func TestSendMessageChecksum(t *testing.T) {
req, _ := svc.SendMessageRequest(&sqs.SendMessageInput{
MessageBody: aws.String("test"),
})
req.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageOutput{
MD5OfMessageBody: aws.String("098f6bcd4621d373cade4e832627b4f6"),
MessageId: aws.String("12345"),
}
})
err := req.Send()
assert.NoError(t, err)
}
func TestSendMessageChecksumInvalid(t *testing.T) {
req, _ := svc.SendMessageRequest(&sqs.SendMessageInput{
MessageBody: aws.String("test"),
})
req.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageOutput{
MD5OfMessageBody: aws.String("000"),
MessageId: aws.String("12345"),
}
})
err := req.Send()
assert.Error(t, err)
assert.Equal(t, "InvalidChecksum", err.(awserr.Error).Code())
assert.Contains(t, err.(awserr.Error).Message(), "expected MD5 checksum '000', got '098f6bcd4621d373cade4e832627b4f6'")
}
func TestSendMessageChecksumInvalidNoValidation(t *testing.T) {
s := sqs.New(unit.Session, &aws.Config{
DisableParamValidation: aws.Bool(true),
DisableComputeChecksums: aws.Bool(true),
})
s.Handlers.Send.Clear()
req, _ := s.SendMessageRequest(&sqs.SendMessageInput{
MessageBody: aws.String("test"),
})
req.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageOutput{
MD5OfMessageBody: aws.String("000"),
MessageId: aws.String("12345"),
}
})
err := req.Send()
assert.NoError(t, err)
}
func TestSendMessageChecksumNoInput(t *testing.T) {
req, _ := svc.SendMessageRequest(&sqs.SendMessageInput{})
req.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageOutput{}
})
err := req.Send()
assert.Error(t, err)
assert.Equal(t, "InvalidChecksum", err.(awserr.Error).Code())
assert.Contains(t, err.(awserr.Error).Message(), "cannot compute checksum. missing body")
}
func TestSendMessageChecksumNoOutput(t *testing.T) {
req, _ := svc.SendMessageRequest(&sqs.SendMessageInput{
MessageBody: aws.String("test"),
})
req.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageOutput{}
})
err := req.Send()
assert.Error(t, err)
assert.Equal(t, "InvalidChecksum", err.(awserr.Error).Code())
assert.Contains(t, err.(awserr.Error).Message(), "cannot verify checksum. missing response MD5")
}
func TestRecieveMessageChecksum(t *testing.T) {
req, _ := svc.ReceiveMessageRequest(&sqs.ReceiveMessageInput{})
req.Handlers.Send.PushBack(func(r *request.Request) {
md5 := "098f6bcd4621d373cade4e832627b4f6"
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.ReceiveMessageOutput{
Messages: []*sqs.Message{
{Body: aws.String("test"), MD5OfBody: &md5},
{Body: aws.String("test"), MD5OfBody: &md5},
{Body: aws.String("test"), MD5OfBody: &md5},
{Body: aws.String("test"), MD5OfBody: &md5},
},
}
})
err := req.Send()
assert.NoError(t, err)
}
func TestRecieveMessageChecksumInvalid(t *testing.T) {
req, _ := svc.ReceiveMessageRequest(&sqs.ReceiveMessageInput{})
req.Handlers.Send.PushBack(func(r *request.Request) {
md5 := "098f6bcd4621d373cade4e832627b4f6"
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.ReceiveMessageOutput{
Messages: []*sqs.Message{
{Body: aws.String("test"), MD5OfBody: &md5},
{Body: aws.String("test"), MD5OfBody: aws.String("000"), MessageId: aws.String("123")},
{Body: aws.String("test"), MD5OfBody: aws.String("000"), MessageId: aws.String("456")},
{Body: aws.String("test"), MD5OfBody: aws.String("000")},
{Body: aws.String("test"), MD5OfBody: &md5},
},
}
})
err := req.Send()
assert.Error(t, err)
assert.Equal(t, "InvalidChecksum", err.(awserr.Error).Code())
assert.Contains(t, err.(awserr.Error).Message(), "invalid messages: 123, 456")
}
func TestSendMessageBatchChecksum(t *testing.T) {
req, _ := svc.SendMessageBatchRequest(&sqs.SendMessageBatchInput{
Entries: []*sqs.SendMessageBatchRequestEntry{
{Id: aws.String("1"), MessageBody: aws.String("test")},
{Id: aws.String("2"), MessageBody: aws.String("test")},
{Id: aws.String("3"), MessageBody: aws.String("test")},
{Id: aws.String("4"), MessageBody: aws.String("test")},
},
})
req.Handlers.Send.PushBack(func(r *request.Request) {
md5 := "098f6bcd4621d373cade4e832627b4f6"
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageBatchOutput{
Successful: []*sqs.SendMessageBatchResultEntry{
{MD5OfMessageBody: &md5, MessageId: aws.String("123"), Id: aws.String("1")},
{MD5OfMessageBody: &md5, MessageId: aws.String("456"), Id: aws.String("2")},
{MD5OfMessageBody: &md5, MessageId: aws.String("789"), Id: aws.String("3")},
{MD5OfMessageBody: &md5, MessageId: aws.String("012"), Id: aws.String("4")},
},
}
})
err := req.Send()
assert.NoError(t, err)
}
func TestSendMessageBatchChecksumInvalid(t *testing.T) {
req, _ := svc.SendMessageBatchRequest(&sqs.SendMessageBatchInput{
Entries: []*sqs.SendMessageBatchRequestEntry{
{Id: aws.String("1"), MessageBody: aws.String("test")},
{Id: aws.String("2"), MessageBody: aws.String("test")},
{Id: aws.String("3"), MessageBody: aws.String("test")},
{Id: aws.String("4"), MessageBody: aws.String("test")},
},
})
req.Handlers.Send.PushBack(func(r *request.Request) {
md5 := "098f6bcd4621d373cade4e832627b4f6"
body := ioutil.NopCloser(bytes.NewReader([]byte("")))
r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
r.Data = &sqs.SendMessageBatchOutput{
Successful: []*sqs.SendMessageBatchResultEntry{
{MD5OfMessageBody: &md5, MessageId: aws.String("123"), Id: aws.String("1")},
{MD5OfMessageBody: aws.String("000"), MessageId: aws.String("456"), Id: aws.String("2")},
{MD5OfMessageBody: aws.String("000"), MessageId: aws.String("789"), Id: aws.String("3")},
{MD5OfMessageBody: &md5, MessageId: aws.String("012"), Id: aws.String("4")},
},
}
})
err := req.Send()
assert.Error(t, err)
assert.Equal(t, "InvalidChecksum", err.(awserr.Error).Code())
assert.Contains(t, err.(awserr.Error).Message(), "invalid messages: 456, 789")
}
+9
View File
@@ -0,0 +1,9 @@
package sqs
import "github.com/aws/aws-sdk-go/aws/request"
func init() {
initRequest = func(r *request.Request) {
setupChecksumValidation(r)
}
}
+115
View File
@@ -0,0 +1,115 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// Package sqs provides the client and types for making API
// requests to Amazon Simple Queue Service.
//
// Welcome to the Amazon Simple Queue Service API Reference.
//
// Amazon Simple Queue Service (Amazon SQS) is a reliable, highly-scalable hosted
// queue for storing messages as they travel between applications or microservices.
// Amazon SQS moves data between distributed application components and helps
// you decouple these components.
//
// Standard queues (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues.html)
// are available in all regions. FIFO queues (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html)
// are available in US West (Oregon) and US East (Ohio).
//
// You can use AWS SDKs (http://aws.amazon.com/tools/#sdk) to access Amazon
// SQS using your favorite programming language. The SDKs perform tasks such
// as the following automatically:
//
// * Cryptographically sign your service requests
//
// * Retry requests
//
// * Handle error responses
//
// Additional Information
//
// * Amazon SQS Product Page (http://aws.amazon.com/sqs/)
//
// * Amazon SQS Developer Guide
//
// Making API Requests (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/MakingRequestsArticle.html)
//
// Using Amazon SQS Message Attributes (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html)
//
// Using Amazon SQS Dead Letter Queues (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html)
//
// * Amazon Web Services General Reference
//
// Regions and Endpoints (http://docs.aws.amazon.com/general/latest/gr/rande.html#sqs_region)
//
// See https://docs.aws.amazon.com/goto/WebAPI/sqs-2012-11-05 for more information on this service.
//
// See sqs package documentation for more information.
// https://docs.aws.amazon.com/sdk-for-go/api/service/sqs/
//
// Using the Client
//
// To use the client for Amazon Simple Queue Service you will first need
// to create a new instance of it.
//
// When creating a client for an AWS service you'll first need to have a Session
// already created. The Session provides configuration that can be shared
// between multiple service clients. Additional configuration can be applied to
// the Session and service's client when they are constructed. The aws package's
// Config type contains several fields such as Region for the AWS Region the
// client should make API requests too. The optional Config value can be provided
// as the variadic argument for Sessions and client creation.
//
// Once the service's client is created you can use it to make API requests the
// AWS service. These clients are safe to use concurrently.
//
// // Create a session to share configuration, and load external configuration.
// sess := session.Must(session.NewSession())
//
// // Create the service's client with the session.
// svc := sqs.New(sess)
//
// See the SDK's documentation for more information on how to use service clients.
// https://docs.aws.amazon.com/sdk-for-go/api/
//
// See aws package's Config type for more information on configuration options.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
//
// See the Amazon Simple Queue Service client SQS for more
// information on creating the service's client.
// https://docs.aws.amazon.com/sdk-for-go/api/service/sqs/#New
//
// Once the client is created you can make an API request to the service.
// Each API method takes a input parameter, and returns the service response
// and an error.
//
// The API method will document which error codes the service can be returned
// by the operation if the service models the API operation's errors. These
// errors will also be available as const strings prefixed with "ErrCode".
//
// result, err := svc.AddPermission(params)
// if err != nil {
// // Cast err to awserr.Error to handle specific error codes.
// aerr, ok := err.(awserr.Error)
// if ok && aerr.Code() == <error code to check for> {
// // Specific error code handling
// }
// return err
// }
//
// fmt.Println("AddPermission result:")
// fmt.Println(result)
//
// Using the Client with Context
//
// The service's client also provides methods to make API requests with a Context
// value. This allows you to control the timeout, and cancellation of pending
// requests. These methods also take request Option as variadic parameter to apply
// additional configuration to the API request.
//
// ctx := context.Background()
//
// result, err := svc.AddPermissionWithContext(ctx, params)
//
// See the request package documentation for more information on using Context pattern
// with the SDK.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/request/
package sqs
+110
View File
@@ -0,0 +1,110 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package sqs
const (
// ErrCodeBatchEntryIdsNotDistinct for service response error code
// "AWS.SimpleQueueService.BatchEntryIdsNotDistinct".
//
// Two or more batch entries in the request have the same Id.
ErrCodeBatchEntryIdsNotDistinct = "AWS.SimpleQueueService.BatchEntryIdsNotDistinct"
// ErrCodeBatchRequestTooLong for service response error code
// "AWS.SimpleQueueService.BatchRequestTooLong".
//
// The length of all the messages put together is more than the limit.
ErrCodeBatchRequestTooLong = "AWS.SimpleQueueService.BatchRequestTooLong"
// ErrCodeEmptyBatchRequest for service response error code
// "AWS.SimpleQueueService.EmptyBatchRequest".
//
// The batch request doesn't contain any entries.
ErrCodeEmptyBatchRequest = "AWS.SimpleQueueService.EmptyBatchRequest"
// ErrCodeInvalidAttributeName for service response error code
// "InvalidAttributeName".
//
// The attribute referred to doesn't exist.
ErrCodeInvalidAttributeName = "InvalidAttributeName"
// ErrCodeInvalidBatchEntryId for service response error code
// "AWS.SimpleQueueService.InvalidBatchEntryId".
//
// The Id of a batch entry in a batch request doesn't abide by the specification.
ErrCodeInvalidBatchEntryId = "AWS.SimpleQueueService.InvalidBatchEntryId"
// ErrCodeInvalidIdFormat for service response error code
// "InvalidIdFormat".
//
// The receipt handle isn't valid for the current version.
ErrCodeInvalidIdFormat = "InvalidIdFormat"
// ErrCodeInvalidMessageContents for service response error code
// "InvalidMessageContents".
//
// The message contains characters outside the allowed set.
ErrCodeInvalidMessageContents = "InvalidMessageContents"
// ErrCodeMessageNotInflight for service response error code
// "AWS.SimpleQueueService.MessageNotInflight".
//
// The message referred to isn't in flight.
ErrCodeMessageNotInflight = "AWS.SimpleQueueService.MessageNotInflight"
// ErrCodeOverLimit for service response error code
// "OverLimit".
//
// The action that you requested would violate a limit. For example, ReceiveMessage
// returns this error if the maximum number of inflight messages is reached.
// AddPermission returns this error if the maximum number of permissions for
// the queue is reached.
ErrCodeOverLimit = "OverLimit"
// ErrCodePurgeQueueInProgress for service response error code
// "AWS.SimpleQueueService.PurgeQueueInProgress".
//
// Indicates that the specified queue previously received a PurgeQueue request
// within the last 60 seconds (the time it can take to delete the messages in
// the queue).
ErrCodePurgeQueueInProgress = "AWS.SimpleQueueService.PurgeQueueInProgress"
// ErrCodeQueueDeletedRecently for service response error code
// "AWS.SimpleQueueService.QueueDeletedRecently".
//
// You must wait 60 seconds after deleting a queue before you can create another
// one with the same name.
ErrCodeQueueDeletedRecently = "AWS.SimpleQueueService.QueueDeletedRecently"
// ErrCodeQueueDoesNotExist for service response error code
// "AWS.SimpleQueueService.NonExistentQueue".
//
// The queue referred to doesn't exist.
ErrCodeQueueDoesNotExist = "AWS.SimpleQueueService.NonExistentQueue"
// ErrCodeQueueNameExists for service response error code
// "QueueAlreadyExists".
//
// A queue already exists with this name. Amazon SQS returns this error only
// if the request includes attributes whose values differ from those of the
// existing queue.
ErrCodeQueueNameExists = "QueueAlreadyExists"
// ErrCodeReceiptHandleIsInvalid for service response error code
// "ReceiptHandleIsInvalid".
//
// The receipt handle provided isn't valid.
ErrCodeReceiptHandleIsInvalid = "ReceiptHandleIsInvalid"
// ErrCodeTooManyEntriesInBatchRequest for service response error code
// "AWS.SimpleQueueService.TooManyEntriesInBatchRequest".
//
// The batch request contains more entries than permissible.
ErrCodeTooManyEntriesInBatchRequest = "AWS.SimpleQueueService.TooManyEntriesInBatchRequest"
// ErrCodeUnsupportedOperation for service response error code
// "AWS.SimpleQueueService.UnsupportedOperation".
//
// Error code 400. Unsupported operation.
ErrCodeUnsupportedOperation = "AWS.SimpleQueueService.UnsupportedOperation"
)
+472
View File
@@ -0,0 +1,472 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package sqs_test
import (
"bytes"
"fmt"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
)
var _ time.Duration
var _ bytes.Buffer
func ExampleSQS_AddPermission() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.AddPermissionInput{
AWSAccountIds: []*string{ // Required
aws.String("String"), // Required
// More values...
},
Actions: []*string{ // Required
aws.String("String"), // Required
// More values...
},
Label: aws.String("String"), // Required
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.AddPermission(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_ChangeMessageVisibility() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.ChangeMessageVisibilityInput{
QueueUrl: aws.String("String"), // Required
ReceiptHandle: aws.String("String"), // Required
VisibilityTimeout: aws.Int64(1), // Required
}
resp, err := svc.ChangeMessageVisibility(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_ChangeMessageVisibilityBatch() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.ChangeMessageVisibilityBatchInput{
Entries: []*sqs.ChangeMessageVisibilityBatchRequestEntry{ // Required
{ // Required
Id: aws.String("String"), // Required
ReceiptHandle: aws.String("String"), // Required
VisibilityTimeout: aws.Int64(1),
},
// More values...
},
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.ChangeMessageVisibilityBatch(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_CreateQueue() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.CreateQueueInput{
QueueName: aws.String("String"), // Required
Attributes: map[string]*string{
"Key": aws.String("String"), // Required
// More values...
},
}
resp, err := svc.CreateQueue(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_DeleteMessage() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.DeleteMessageInput{
QueueUrl: aws.String("String"), // Required
ReceiptHandle: aws.String("String"), // Required
}
resp, err := svc.DeleteMessage(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_DeleteMessageBatch() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.DeleteMessageBatchInput{
Entries: []*sqs.DeleteMessageBatchRequestEntry{ // Required
{ // Required
Id: aws.String("String"), // Required
ReceiptHandle: aws.String("String"), // Required
},
// More values...
},
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.DeleteMessageBatch(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_DeleteQueue() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.DeleteQueueInput{
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.DeleteQueue(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_GetQueueAttributes() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.GetQueueAttributesInput{
QueueUrl: aws.String("String"), // Required
AttributeNames: []*string{
aws.String("QueueAttributeName"), // Required
// More values...
},
}
resp, err := svc.GetQueueAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_GetQueueUrl() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.GetQueueUrlInput{
QueueName: aws.String("String"), // Required
QueueOwnerAWSAccountId: aws.String("String"),
}
resp, err := svc.GetQueueUrl(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_ListDeadLetterSourceQueues() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.ListDeadLetterSourceQueuesInput{
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.ListDeadLetterSourceQueues(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_ListQueues() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.ListQueuesInput{
QueueNamePrefix: aws.String("String"),
}
resp, err := svc.ListQueues(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_PurgeQueue() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.PurgeQueueInput{
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.PurgeQueue(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_ReceiveMessage() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.ReceiveMessageInput{
QueueUrl: aws.String("String"), // Required
AttributeNames: []*string{
aws.String("QueueAttributeName"), // Required
// More values...
},
MaxNumberOfMessages: aws.Int64(1),
MessageAttributeNames: []*string{
aws.String("MessageAttributeName"), // Required
// More values...
},
ReceiveRequestAttemptId: aws.String("String"),
VisibilityTimeout: aws.Int64(1),
WaitTimeSeconds: aws.Int64(1),
}
resp, err := svc.ReceiveMessage(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_RemovePermission() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.RemovePermissionInput{
Label: aws.String("String"), // Required
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.RemovePermission(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_SendMessage() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.SendMessageInput{
MessageBody: aws.String("String"), // Required
QueueUrl: aws.String("String"), // Required
DelaySeconds: aws.Int64(1),
MessageAttributes: map[string]*sqs.MessageAttributeValue{
"Key": { // Required
DataType: aws.String("String"), // Required
BinaryListValues: [][]byte{
[]byte("PAYLOAD"), // Required
// More values...
},
BinaryValue: []byte("PAYLOAD"),
StringListValues: []*string{
aws.String("String"), // Required
// More values...
},
StringValue: aws.String("String"),
},
// More values...
},
MessageDeduplicationId: aws.String("String"),
MessageGroupId: aws.String("String"),
}
resp, err := svc.SendMessage(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_SendMessageBatch() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.SendMessageBatchInput{
Entries: []*sqs.SendMessageBatchRequestEntry{ // Required
{ // Required
Id: aws.String("String"), // Required
MessageBody: aws.String("String"), // Required
DelaySeconds: aws.Int64(1),
MessageAttributes: map[string]*sqs.MessageAttributeValue{
"Key": { // Required
DataType: aws.String("String"), // Required
BinaryListValues: [][]byte{
[]byte("PAYLOAD"), // Required
// More values...
},
BinaryValue: []byte("PAYLOAD"),
StringListValues: []*string{
aws.String("String"), // Required
// More values...
},
StringValue: aws.String("String"),
},
// More values...
},
MessageDeduplicationId: aws.String("String"),
MessageGroupId: aws.String("String"),
},
// More values...
},
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.SendMessageBatch(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
func ExampleSQS_SetQueueAttributes() {
sess := session.Must(session.NewSession())
svc := sqs.New(sess)
params := &sqs.SetQueueAttributesInput{
Attributes: map[string]*string{ // Required
"Key": aws.String("String"), // Required
// More values...
},
QueueUrl: aws.String("String"), // Required
}
resp, err := svc.SetQueueAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
+93
View File
@@ -0,0 +1,93 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package sqs
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/client/metadata"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/signer/v4"
"github.com/aws/aws-sdk-go/private/protocol/query"
)
// SQS provides the API operation methods for making requests to
// Amazon Simple Queue Service. See this package's package overview docs
// for details on the service.
//
// SQS methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type SQS struct {
*client.Client
}
// Used for custom client initialization logic
var initClient func(*client.Client)
// Used for custom request initialization logic
var initRequest func(*request.Request)
// Service information constants
const (
ServiceName = "sqs" // Service endpoint prefix API calls made to.
EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
)
// New creates a new instance of the SQS client with a session.
// If additional configuration is needed for the client instance use the optional
// aws.Config parameter to add your extra config.
//
// Example:
// // Create a SQS client from just a session.
// svc := sqs.New(mySession)
//
// // Create a SQS client with additional configuration
// svc := sqs.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func New(p client.ConfigProvider, cfgs ...*aws.Config) *SQS {
c := p.ClientConfig(EndpointsID, cfgs...)
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *SQS {
svc := &SQS{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: ServiceName,
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "2012-11-05",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
svc.Handlers.Build.PushBackNamed(query.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(query.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(query.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(query.UnmarshalErrorHandler)
// Run custom client initialization if present
if initClient != nil {
initClient(svc.Client)
}
return svc
}
// newRequest creates a new request for a SQS operation and runs any
// custom request initialization.
func (c *SQS) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
// Run custom request initialization if present
if initRequest != nil {
initRequest(req)
}
return req
}
+132
View File
@@ -0,0 +1,132 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// Package sqsiface provides an interface to enable mocking the Amazon Simple Queue Service service client
// for testing your code.
//
// It is important to note that this interface will have breaking changes
// when the service model is updated and adds new API operations, paginators,
// and waiters.
package sqsiface
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/sqs"
)
// SQSAPI provides an interface to enable mocking the
// sqs.SQS service client's API operation,
// paginators, and waiters. This make unit testing your code that calls out
// to the SDK's service client's calls easier.
//
// The best way to use this interface is so the SDK's service client's calls
// can be stubbed out for unit testing your code with the SDK without needing
// to inject custom request handlers into the the SDK's request pipeline.
//
// // myFunc uses an SDK service client to make a request to
// // Amazon Simple Queue Service.
// func myFunc(svc sqsiface.SQSAPI) bool {
// // Make svc.AddPermission request
// }
//
// func main() {
// sess := session.New()
// svc := sqs.New(sess)
//
// myFunc(svc)
// }
//
// In your _test.go file:
//
// // Define a mock struct to be used in your unit tests of myFunc.
// type mockSQSClient struct {
// sqsiface.SQSAPI
// }
// func (m *mockSQSClient) AddPermission(input *sqs.AddPermissionInput) (*sqs.AddPermissionOutput, error) {
// // mock response/functionality
// }
//
// func TestMyFunc(t *testing.T) {
// // Setup Test
// mockSvc := &mockSQSClient{}
//
// myfunc(mockSvc)
//
// // Verify myFunc's functionality
// }
//
// It is important to note that this interface will have breaking changes
// when the service model is updated and adds new API operations, paginators,
// and waiters. Its suggested to use the pattern above for testing, or using
// tooling to generate mocks to satisfy the interfaces.
type SQSAPI interface {
AddPermission(*sqs.AddPermissionInput) (*sqs.AddPermissionOutput, error)
AddPermissionWithContext(aws.Context, *sqs.AddPermissionInput, ...request.Option) (*sqs.AddPermissionOutput, error)
AddPermissionRequest(*sqs.AddPermissionInput) (*request.Request, *sqs.AddPermissionOutput)
ChangeMessageVisibility(*sqs.ChangeMessageVisibilityInput) (*sqs.ChangeMessageVisibilityOutput, error)
ChangeMessageVisibilityWithContext(aws.Context, *sqs.ChangeMessageVisibilityInput, ...request.Option) (*sqs.ChangeMessageVisibilityOutput, error)
ChangeMessageVisibilityRequest(*sqs.ChangeMessageVisibilityInput) (*request.Request, *sqs.ChangeMessageVisibilityOutput)
ChangeMessageVisibilityBatch(*sqs.ChangeMessageVisibilityBatchInput) (*sqs.ChangeMessageVisibilityBatchOutput, error)
ChangeMessageVisibilityBatchWithContext(aws.Context, *sqs.ChangeMessageVisibilityBatchInput, ...request.Option) (*sqs.ChangeMessageVisibilityBatchOutput, error)
ChangeMessageVisibilityBatchRequest(*sqs.ChangeMessageVisibilityBatchInput) (*request.Request, *sqs.ChangeMessageVisibilityBatchOutput)
CreateQueue(*sqs.CreateQueueInput) (*sqs.CreateQueueOutput, error)
CreateQueueWithContext(aws.Context, *sqs.CreateQueueInput, ...request.Option) (*sqs.CreateQueueOutput, error)
CreateQueueRequest(*sqs.CreateQueueInput) (*request.Request, *sqs.CreateQueueOutput)
DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)
DeleteMessageWithContext(aws.Context, *sqs.DeleteMessageInput, ...request.Option) (*sqs.DeleteMessageOutput, error)
DeleteMessageRequest(*sqs.DeleteMessageInput) (*request.Request, *sqs.DeleteMessageOutput)
DeleteMessageBatch(*sqs.DeleteMessageBatchInput) (*sqs.DeleteMessageBatchOutput, error)
DeleteMessageBatchWithContext(aws.Context, *sqs.DeleteMessageBatchInput, ...request.Option) (*sqs.DeleteMessageBatchOutput, error)
DeleteMessageBatchRequest(*sqs.DeleteMessageBatchInput) (*request.Request, *sqs.DeleteMessageBatchOutput)
DeleteQueue(*sqs.DeleteQueueInput) (*sqs.DeleteQueueOutput, error)
DeleteQueueWithContext(aws.Context, *sqs.DeleteQueueInput, ...request.Option) (*sqs.DeleteQueueOutput, error)
DeleteQueueRequest(*sqs.DeleteQueueInput) (*request.Request, *sqs.DeleteQueueOutput)
GetQueueAttributes(*sqs.GetQueueAttributesInput) (*sqs.GetQueueAttributesOutput, error)
GetQueueAttributesWithContext(aws.Context, *sqs.GetQueueAttributesInput, ...request.Option) (*sqs.GetQueueAttributesOutput, error)
GetQueueAttributesRequest(*sqs.GetQueueAttributesInput) (*request.Request, *sqs.GetQueueAttributesOutput)
GetQueueUrl(*sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error)
GetQueueUrlWithContext(aws.Context, *sqs.GetQueueUrlInput, ...request.Option) (*sqs.GetQueueUrlOutput, error)
GetQueueUrlRequest(*sqs.GetQueueUrlInput) (*request.Request, *sqs.GetQueueUrlOutput)
ListDeadLetterSourceQueues(*sqs.ListDeadLetterSourceQueuesInput) (*sqs.ListDeadLetterSourceQueuesOutput, error)
ListDeadLetterSourceQueuesWithContext(aws.Context, *sqs.ListDeadLetterSourceQueuesInput, ...request.Option) (*sqs.ListDeadLetterSourceQueuesOutput, error)
ListDeadLetterSourceQueuesRequest(*sqs.ListDeadLetterSourceQueuesInput) (*request.Request, *sqs.ListDeadLetterSourceQueuesOutput)
ListQueues(*sqs.ListQueuesInput) (*sqs.ListQueuesOutput, error)
ListQueuesWithContext(aws.Context, *sqs.ListQueuesInput, ...request.Option) (*sqs.ListQueuesOutput, error)
ListQueuesRequest(*sqs.ListQueuesInput) (*request.Request, *sqs.ListQueuesOutput)
PurgeQueue(*sqs.PurgeQueueInput) (*sqs.PurgeQueueOutput, error)
PurgeQueueWithContext(aws.Context, *sqs.PurgeQueueInput, ...request.Option) (*sqs.PurgeQueueOutput, error)
PurgeQueueRequest(*sqs.PurgeQueueInput) (*request.Request, *sqs.PurgeQueueOutput)
ReceiveMessage(*sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)
ReceiveMessageWithContext(aws.Context, *sqs.ReceiveMessageInput, ...request.Option) (*sqs.ReceiveMessageOutput, error)
ReceiveMessageRequest(*sqs.ReceiveMessageInput) (*request.Request, *sqs.ReceiveMessageOutput)
RemovePermission(*sqs.RemovePermissionInput) (*sqs.RemovePermissionOutput, error)
RemovePermissionWithContext(aws.Context, *sqs.RemovePermissionInput, ...request.Option) (*sqs.RemovePermissionOutput, error)
RemovePermissionRequest(*sqs.RemovePermissionInput) (*request.Request, *sqs.RemovePermissionOutput)
SendMessage(*sqs.SendMessageInput) (*sqs.SendMessageOutput, error)
SendMessageWithContext(aws.Context, *sqs.SendMessageInput, ...request.Option) (*sqs.SendMessageOutput, error)
SendMessageRequest(*sqs.SendMessageInput) (*request.Request, *sqs.SendMessageOutput)
SendMessageBatch(*sqs.SendMessageBatchInput) (*sqs.SendMessageBatchOutput, error)
SendMessageBatchWithContext(aws.Context, *sqs.SendMessageBatchInput, ...request.Option) (*sqs.SendMessageBatchOutput, error)
SendMessageBatchRequest(*sqs.SendMessageBatchInput) (*request.Request, *sqs.SendMessageBatchOutput)
SetQueueAttributes(*sqs.SetQueueAttributesInput) (*sqs.SetQueueAttributesOutput, error)
SetQueueAttributesWithContext(aws.Context, *sqs.SetQueueAttributesInput, ...request.Option) (*sqs.SetQueueAttributesOutput, error)
SetQueueAttributesRequest(*sqs.SetQueueAttributesInput) (*request.Request, *sqs.SetQueueAttributesOutput)
}
var _ SQSAPI = (*sqs.SQS)(nil)