Skip to content

Commit

Permalink
Finish documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cataldo committed Dec 15, 2023
1 parent a5d4b07 commit bb0f821
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 61 deletions.
22 changes: 11 additions & 11 deletions sqs/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func initListTestProducer() []testProducer {
v: initTestStruct(),
opts: []option.Producer{
option.NewProducer().SetDebugMode(true),
option.NewProducer().SetOptionHttp(option.Http{}),
option.NewProducer().SetHttpClient(option.HttpClient{}),
option.NewProducer().SetMessageAttributes(initMessageAttTest()),
option.NewProducer().SetMessageGroupId("group"),
option.NewProducer().SetMessageDeduplicationId("deduplication"),
Expand Down Expand Up @@ -880,7 +880,7 @@ func initStartMessageMoveTaskInput() StartMessageMoveTaskInput {
func initOptionsConsumerDefault() []option.Consumer {
return []option.Consumer{
option.NewConsumer().SetDebugMode(true),
option.NewConsumer().SetOptionHttp(option.Http{}),
option.NewConsumer().SetHttpClient(option.HttpClient{}),
option.NewConsumer().SetConsumerMessageTimeout(5 * time.Second),
option.NewConsumer().SetDelayQueryLoop(4 * time.Second),
option.NewConsumer().SetDeleteMessageProcessedSuccess(true),
Expand All @@ -894,7 +894,7 @@ func initOptionsConsumerDefault() []option.Consumer {
func initOptionsConsumerWithErr() []option.Consumer {
return []option.Consumer{
option.NewConsumer().SetDebugMode(true),
option.NewConsumer().SetOptionHttp(option.Http{}),
option.NewConsumer().SetHttpClient(option.HttpClient{}),
option.NewConsumer().SetConsumerMessageTimeout(0),
option.NewConsumer().SetDelayQueryLoop(0),
option.NewConsumer().SetDeleteMessageProcessedSuccess(true),
Expand All @@ -908,7 +908,7 @@ func initOptionsConsumerWithErr() []option.Consumer {
func initOptionsCreateQueue() []option.CreateQueue {
return []option.CreateQueue{
option.NewCreateQueue().SetDebugMode(true),
option.NewCreateQueue().SetOptionHttp(option.Http{}),
option.NewCreateQueue().SetHttpClient(option.HttpClient{}),
option.NewCreateQueue().SetAttributes(initAttributesQueue("800")),
option.NewCreateQueue().SetTags(initTagsQueue()),
}
Expand All @@ -917,7 +917,7 @@ func initOptionsCreateQueue() []option.CreateQueue {
func initOptionsListQueues() []option.ListQueues {
return []option.ListQueues{
option.NewListQueue().SetDebugMode(true),
option.NewListQueue().SetOptionHttp(option.Http{}),
option.NewListQueue().SetHttpClient(option.HttpClient{}),
option.NewListQueue().SetMaxResults(0),
option.NewListQueue().SetNextToken(""),
option.NewListQueue().SetQueueNamePrefix(""),
Expand All @@ -927,7 +927,7 @@ func initOptionsListQueues() []option.ListQueues {
func initOptionsListQueuesWithErr() []option.ListQueues {
return []option.ListQueues{
option.NewListQueue().SetDebugMode(true),
option.NewListQueue().SetOptionHttp(option.Http{}),
option.NewListQueue().SetHttpClient(option.HttpClient{}),
option.NewListQueue().SetMaxResults(10),
option.NewListQueue().SetNextToken("test"),
option.NewListQueue().SetQueueNamePrefix("test"),
Expand All @@ -937,7 +937,7 @@ func initOptionsListQueuesWithErr() []option.ListQueues {
func initOptionsListDeadLetterSourceQueues() []option.ListDeadLetterSourceQueues {
return []option.ListDeadLetterSourceQueues{
option.NewListDeadLetterSourceQueues().SetDebugMode(true),
option.NewListDeadLetterSourceQueues().SetOptionHttp(option.Http{}),
option.NewListDeadLetterSourceQueues().SetHttpClient(option.HttpClient{}),
option.NewListDeadLetterSourceQueues().SetMaxResults(0),
option.NewListDeadLetterSourceQueues().SetNextToken(""),
}
Expand All @@ -946,7 +946,7 @@ func initOptionsListDeadLetterSourceQueues() []option.ListDeadLetterSourceQueues
func initOptionsListDeadLetterSourceQueuesWithErr() []option.ListDeadLetterSourceQueues {
return []option.ListDeadLetterSourceQueues{
option.NewListDeadLetterSourceQueues().SetDebugMode(true),
option.NewListDeadLetterSourceQueues().SetOptionHttp(option.Http{}),
option.NewListDeadLetterSourceQueues().SetHttpClient(option.HttpClient{}),
option.NewListDeadLetterSourceQueues().SetMaxResults(10),
option.NewListDeadLetterSourceQueues().SetNextToken("token token"),
}
Expand All @@ -955,22 +955,22 @@ func initOptionsListDeadLetterSourceQueuesWithErr() []option.ListDeadLetterSourc
func initOptionsDefault() []option.Default {
return []option.Default{
option.NewDefault().SetDebugMode(true),
option.NewDefault().SetOptionHttp(option.Http{}),
option.NewDefault().SetHttpClient(option.HttpClient{}),
}
}

func initOptionsListMessageMoveTasks() []option.ListMessageMoveTasks {
return []option.ListMessageMoveTasks{
option.NewListMessageMoveTasks().SetDebugMode(true),
option.NewListMessageMoveTasks().SetOptionHttp(option.Http{}),
option.NewListMessageMoveTasks().SetHttpClient(option.HttpClient{}),
option.NewListMessageMoveTasks().SetMaxResults(10),
}
}

func initOptionsListMessageMoveTasksWithErr() []option.ListMessageMoveTasks {
return []option.ListMessageMoveTasks{
option.NewListMessageMoveTasks().SetDebugMode(true),
option.NewListMessageMoveTasks().SetOptionHttp(option.Http{}),
option.NewListMessageMoveTasks().SetHttpClient(option.HttpClient{}),
option.NewListMessageMoveTasks().SetMaxResults(0),
}
}
Expand Down
14 changes: 7 additions & 7 deletions sqs/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func DeleteMessage(ctx context.Context, queueUrl, receiptHandle string, opts ...
output, err := sqsClient.DeleteMessage(ctx, &sqs.DeleteMessageInput{
QueueUrl: &queueUrl,
ReceiptHandle: &receiptHandle,
}, option.FuncByOptionHttp(opt.OptionHttp))
}, option.FuncByHttpClient(opt.HttpClient))
if err != nil {
loggerErr(opt.DebugMode, "error delete message:", err)
} else {
Expand All @@ -151,7 +151,7 @@ func DeleteMessageBatch(ctx context.Context, input DeleteMessageBatchInput, opts
output, err := sqsClient.DeleteMessageBatch(ctx, &sqs.DeleteMessageBatchInput{
Entries: prepareEntriesDeleteMessageBatch(input.Entries),
QueueUrl: &input.QueueUrl,
}, option.FuncByOptionHttp(opt.OptionHttp))
}, option.FuncByHttpClient(opt.HttpClient))
if err != nil {
loggerErr(opt.DebugMode, "error delete messages batch:", err)
} else {
Expand Down Expand Up @@ -210,7 +210,7 @@ func ChangeMessageVisibility(ctx context.Context, input ChangeMessageVisibilityI
QueueUrl: &input.QueueUrl,
ReceiptHandle: &input.ReceiptHandle,
VisibilityTimeout: util.ConvertDurationToInt32(input.VisibilityTimeout),
}, option.FuncByOptionHttp(opt.OptionHttp))
}, option.FuncByHttpClient(opt.HttpClient))
if err != nil {
loggerErr(opt.DebugMode, "error charge message visibility:", err)
} else {
Expand All @@ -234,7 +234,7 @@ func ChangeMessageVisibilityBatch(ctx context.Context, input ChangeMessageVisibi
output, err := sqsClient.ChangeMessageVisibilityBatch(ctx, &sqs.ChangeMessageVisibilityBatchInput{
Entries: prepareEntriesChangeMessageVisibilityBatch(input.Entries),
QueueUrl: &input.QueueUrl,
}, option.FuncByOptionHttp(opt.OptionHttp))
}, option.FuncByHttpClient(opt.HttpClient))
if err != nil {
loggerErr(opt.DebugMode, "error charge message visibility batch:", err)
} else {
Expand Down Expand Up @@ -266,7 +266,7 @@ func StartMessageMoveTask(ctx context.Context, input StartMessageMoveTaskInput,
SourceArn: &input.SourceArn,
DestinationArn: input.DestinationArn,
MaxNumberOfMessagesPerSecond: input.MaxNumberOfMessagesPerSecond,
}, option.FuncByOptionHttp(opt.OptionHttp))
}, option.FuncByHttpClient(opt.HttpClient))
if err != nil {
loggerErr(opt.DebugMode, "error start message move task:", err)
} else {
Expand Down Expand Up @@ -294,7 +294,7 @@ func CancelMessageMoveTask(ctx context.Context, taskHandle string, opts ...optio
sqsClient := client.GetClient(ctx)
output, err := sqsClient.CancelMessageMoveTask(ctx, &sqs.CancelMessageMoveTaskInput{
TaskHandle: &taskHandle,
}, option.FuncByOptionHttp(opt.OptionHttp))
}, option.FuncByHttpClient(opt.HttpClient))
if err != nil {
loggerErr(opt.DebugMode, "error cancel message move task:", err)
} else {
Expand All @@ -321,7 +321,7 @@ func ListMessageMoveTasks(ctx context.Context, sourceArn string, opts ...option.
output, err := sqsClient.ListMessageMoveTasks(ctx, &sqs.ListMessageMoveTasksInput{
SourceArn: &sourceArn,
MaxResults: &opt.MaxResults,
}, option.FuncByOptionHttp(opt.OptionHttp))
}, option.FuncByHttpClient(opt.HttpClient))
if err != nil {
loggerErr(opt.DebugMode, "error list message move tasks:", err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions sqs/option/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (o Consumer) SetDebugMode(b bool) Consumer {
return o
}

func (o Consumer) SetOptionHttp(opt Http) Consumer {
o.OptionHttp = &opt
func (o Consumer) SetHttpClient(opt HttpClient) Consumer {
o.HttpClient = &opt
return o
}

Expand Down
14 changes: 8 additions & 6 deletions sqs/option/default.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package option

type Default struct {
OptionHttp *Http `json:"optionsHttp,omitempty"`
DebugMode bool `json:"debugMode,omitempty"`
// HTTP communication customization options with AWS SQS
HttpClient *HttpClient `json:"httpClient,omitempty"`
// if true and print all information and error logs
DebugMode bool `json:"debugMode,omitempty"`
}

func NewDefault() Default {
Expand All @@ -14,8 +16,8 @@ func (o Default) SetDebugMode(b bool) Default {
return o
}

func (o Default) SetOptionHttp(opt Http) Default {
o.OptionHttp = &opt
func (o Default) SetHttpClient(httpClient HttpClient) Default {
o.HttpClient = &httpClient
return o
}

Expand All @@ -31,7 +33,7 @@ func fillDefaultFields(opt Default, dest *Default) {
if opt.DebugMode {
dest.DebugMode = true
}
if opt.OptionHttp != nil {
dest.OptionHttp = opt.OptionHttp
if opt.HttpClient != nil {
dest.HttpClient = opt.HttpClient
}
}
6 changes: 3 additions & 3 deletions sqs/option/http.go → sqs/option/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
smithyhttp "github.com/aws/smithy-go/transport/http"
)

type Http struct {
type HttpClient struct {
// Set of options to modify how an operation is invoked. These apply to all
// operations invoked for this sqsClient. Use functional options on operation call to
// modify this list for per operation behavior.
Expand Down Expand Up @@ -66,7 +66,7 @@ type Http struct {
RuntimeEnvironment aws.RuntimeEnvironment
// The initial DefaultsMode used when the client options were constructed. If the
// DefaultsMode was set to aws.DefaultsModeAuto this will store what the resolved
// value was at that point in time. Currently does not support per operation call
// value was at that point in time. Currently, does not support per operation call
// overrides, may in the future.
resolvedDefaultsMode aws.DefaultsMode
// The HTTP client to invoke API calls with. Defaults to client's default HTTP
Expand All @@ -79,7 +79,7 @@ type Http struct {
AuthSchemes []smithyhttp.AuthScheme
}

func FuncByOptionHttp(opt *Http) func(options *sqs.Options) {
func FuncByHttpClient(opt *HttpClient) func(options *sqs.Options) {
return func(options *sqs.Options) {
if opt == nil {
return
Expand Down
4 changes: 2 additions & 2 deletions sqs/option/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func (o ListMessageMoveTasks) SetDebugMode(b bool) ListMessageMoveTasks {
return o
}

func (o ListMessageMoveTasks) SetOptionHttp(opt Http) ListMessageMoveTasks {
o.OptionHttp = &opt
func (o ListMessageMoveTasks) SetHttpClient(opt HttpClient) ListMessageMoveTasks {
o.HttpClient = &opt
return o
}

Expand Down
81 changes: 75 additions & 6 deletions sqs/option/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,83 @@ import (

type Producer struct {
Default
DelaySeconds time.Duration `json:"delaySeconds,omitempty"`
MessageAttributes any `json:"messageAttributes,omitempty"`
// The length of time, in seconds, for which to delay a specific message. Maximum: 15 minutes.
// Messages with a positive DelaySeconds value become available for processing after the delay period is finished.
// If you don't specify a value, the default value for the queue applies. When you set
// FifoQueue , you can't set DelaySeconds per message. You can set this parameter
// only on a queue level.
DelaySeconds time.Duration `json:"delaySeconds,omitempty"`
// Message attributes, must be of type Map or Struct, other types are not acceptable.
MessageAttributes any `json:"messageAttributes,omitempty"`
// The message system attribute to send.
// - Currently, the only supported message system attribute is AWSTraceHeader .
// Its type must be String and its value must be a correctly formatted X-Ray
// trace header string.
// - The size of a message system attribute doesn't count towards the total size
// of a message.
MessageSystemAttributes *MessageSystemAttributes `json:"messageSystemAttributes,omitempty"`
MessageDeduplicationId *string `json:"messageDeduplicationId,omitempty"`
MessageGroupId *string `json:"messageGroupId,omitempty"`
// This parameter applies only to FIFO (first-in-first-out) queues. The token used
// for deduplication of sent messages. If a message with a particular
// MessageDeduplicationId is sent successfully, any messages sent with the same
// MessageDeduplicationId are accepted successfully but aren't delivered during the
// 5-minute deduplication interval. For more information, see Exactly-once
// processing (https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues-exactly-once-processing.html)
// in the Amazon SQS Developer Guide.
// - Every message must have a unique MessageDeduplicationId ,
// - You may provide a MessageDeduplicationId explicitly.
// - If you aren't able to provide a MessageDeduplicationId and you enable
// ContentBasedDeduplication for your queue, Amazon SQS uses a SHA-256 hash to
// generate the MessageDeduplicationId using the body of the message (but not the
// attributes of the message).
// - If you don't provide a MessageDeduplicationId and the queue doesn't have
// ContentBasedDeduplication set, the action fails with an error.
// - If the queue has ContentBasedDeduplication set, your MessageDeduplicationId
// overrides the generated one.
// - When ContentBasedDeduplication is in effect, messages with identical content
// sent within the deduplication interval are treated as duplicates and only one
// copy of the message is delivered.
// - If you send one message with ContentBasedDeduplication enabled and then
// another message with a MessageDeduplicationId that is the same as the one
// generated for the first MessageDeduplicationId , the two messages are treated
// as duplicates and only one copy of the message is delivered.
// The MessageDeduplicationId is available to the consumer of the message (this
// can be useful for troubleshooting delivery issues). If a message is sent
// successfully but the acknowledgement is lost and the message is resent with the
// same MessageDeduplicationId after the deduplication interval, Amazon SQS can't
// detect duplicate messages. Amazon SQS continues to keep track of the message
// deduplication ID even after the message is received and deleted. The maximum
// length of MessageDeduplicationId is 128 characters. MessageDeduplicationId can
// contain alphanumeric characters ( a-z , A-Z , 0-9 ) and punctuation (
// !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ ). For best practices of using
// MessageDeduplicationId , see Using the MessageDeduplicationId Property (https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagededuplicationid-property.html)
// in the Amazon SQS Developer Guide.
MessageDeduplicationId *string `json:"messageDeduplicationId,omitempty"`
// This parameter applies only to FIFO (first-in-first-out) queues. The tag that
// specifies that a message belongs to a specific message group. Messages that
// belong to the same message group are processed in a FIFO manner (however,
// messages in different message groups might be processed out of order). To
// interleave multiple ordered streams within a single queue, use MessageGroupId
// values (for example, session data for multiple users). In this scenario,
// multiple consumers can process the queue, but the session data of each user is
// processed in a FIFO fashion.
// - You must associate a non-empty MessageGroupId with a message. If you don't
// provide a MessageGroupId , the action fails.
// - ReceiveMessage might return messages with multiple MessageGroupId values.
// For each MessageGroupId , the messages are sorted by time sent. The caller
// can't specify a MessageGroupId .
// The length of MessageGroupId is 128 characters. Valid values: alphanumeric
// characters and punctuation (!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~) . For best
// practices of using MessageGroupId , see Using the MessageGroupId Property (https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/using-messagegroupid-property.html)
// in the Amazon SQS Developer Guide. MessageGroupId is required for FIFO queues.
// You can't use it for Standard queues.
MessageGroupId *string `json:"messageGroupId,omitempty"`
}

type MessageSystemAttributes struct {
// its value must be a correctly formatted X-Ray
// trace header string.
//
// this member is required
AWSTraceHeader string `json:"AWSTraceHeader,omitempty"`
}

Expand Down Expand Up @@ -52,8 +121,8 @@ func (o Producer) SetDebugMode(b bool) Producer {
return o
}

func (o Producer) SetOptionHttp(opt Http) Producer {
o.OptionHttp = &opt
func (o Producer) SetHttpClient(opt HttpClient) Producer {
o.HttpClient = &opt
return o
}

Expand Down
12 changes: 6 additions & 6 deletions sqs/option/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (o CreateQueue) SetDebugMode(b bool) CreateQueue {
return o
}

func (o CreateQueue) SetOptionHttp(opt Http) CreateQueue {
o.OptionHttp = &opt
func (o CreateQueue) SetHttpClient(opt HttpClient) CreateQueue {
o.HttpClient = &opt
return o
}

Expand All @@ -205,8 +205,8 @@ func (o ListQueues) SetDebugMode(b bool) ListQueues {
return o
}

func (o ListQueues) SetOptionHttp(opt Http) ListQueues {
o.OptionHttp = &opt
func (o ListQueues) SetHttpClient(opt HttpClient) ListQueues {
o.HttpClient = &opt
return o
}

Expand All @@ -230,8 +230,8 @@ func (o ListDeadLetterSourceQueues) SetDebugMode(b bool) ListDeadLetterSourceQue
return o
}

func (o ListDeadLetterSourceQueues) SetOptionHttp(opt Http) ListDeadLetterSourceQueues {
o.OptionHttp = &opt
func (o ListDeadLetterSourceQueues) SetHttpClient(opt HttpClient) ListDeadLetterSourceQueues {
o.HttpClient = &opt
return o
}

Expand Down
Loading

0 comments on commit bb0f821

Please sign in to comment.