client

package
v1.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	// The `Key` field is defining a string property named `Key` for the `Attribute` struct. This property
	// represents the name of the attribute.
	Key string
	// The `Value` field is defining a string property named `Value` for the `Attribute` struct. This
	// property represents the value of an HTML attribute. In the context of the `Attribute` struct, it is
	// used to store the value of an attribute that can be used to provide additional information about the
	// message being sent to the queue.
	Value string
	// The `Type` field in the `Attribute` struct is defining a string property named `Type` that
	// represents the data type of the attribute's value. It could be "text", "number", "date", "boolean",
	// or any other data type that is relevant to the attribute's purpose. This field is optional and can
	// be used to provide additional information about the attribute.
	Type string
}

The Attribute type represents an HTML attribute with a key, value, and type. @property {string} Key - A string representing the name of the attribute. @property {string} Value - The "Value" property is a string type that represents the value of an attribute. In the context of the "Attribute" struct, it is used to store the value of an HTML attribute. @property {string} Type - The "Type" property is a string that represents the type of the attribute. It could be "text", "number", "date", "boolean", or any other data type that is relevant to the attribute's purpose.

type AwsConfig

type AwsConfig struct {
	// `Endpoint` is a field in the `AwsConfig` struct that represents the endpoint for the AWS service. It
	// is a string type. The `WithEndpoint` function is an `AwsConfigOption` that sets the value of this
	// field when passed as an argument to `NewAwsConfig` function.
	Endpoint string
	// `Region` is a field in the `AwsConfig` struct that represents the region for the AWS service. It is
	// a string type. The `WithRegion` function is an `AwsConfigOption` that sets the value of this field
	// when passed as an argument to `NewAwsConfig` function.
	Region string
	// `Profile` is a field in the `AwsConfig` struct that represents the AWS profile to use for
	// authentication. It is a string type. The `WithProfile` function is an `AwsConfigOption` that sets
	// the value of this field when passed as an argument to `NewAwsConfig` function.
	Profile string
	// The `ID` field is a string type field in the `AwsConfig` struct that represents the AWS access key
	// ID to use for authentication. It can be set using the `WithID` function, which is an
	// `AwsConfigOption` that sets the value of this field when passed as an argument to the `NewAwsConfig`
	// function.
	ID string
	// The `Secret` field is a string type field in the `AwsConfig` struct that represents the AWS secret
	// access key to use for authentication. It can be set using the `WithSecret` function, which is an
	// `AwsConfigOption` that sets the value of this field when passed as an argument to the `NewAwsConfig`
	// function.
	Secret string
	// `UseS3PathStyleAddressing` is a boolean field in the `AwsConfig` struct that determines whether to
	// use path-style or virtual-hosted style addressing when making requests to Amazon S3. If it is set
	// to `true`, path-style addressing will be used, and if it is set to `false`, virtual-hosted style
	// addressing will be used. This option is set using the `WithUseS3PathStyleAddressing` function,
	// which is an `AwsConfigOption` that sets the value of this field when passed as an argument to the
	// `NewAwsConfig` function.
	UseS3PathStyleAddressing bool
}

The `AwsConfig` struct represents the configuration options for an AWS service, including endpoint, region, authentication credentials, and S3 addressing style. @property {string} Endpoint - represents the endpoint for the AWS service. @property {string} Region - The `Region` field in the `AwsConfig` struct represents the region for the AWS service. It is a string type and can be set using the `WithRegion` function, which is an `AwsConfigOption` that sets the value of this field when passed as an argument to the ` @property {string} Profile - The `Profile` field in the `AwsConfig` struct represents the AWS profile to use for authentication. It is a string type and can be set using the `WithProfile` function, which is an `AwsConfigOption` that sets the value of this field when passed as an argument to the @property {string} ID - The `ID` field is a string type field in the `AwsConfig` struct that represents the AWS access key ID to use for authentication. It can be set using the `WithID` function, which is an `AwsConfigOption` that sets the value of this field when passed as an @property {string} Secret - The `Secret` field is a string type field in the `AwsConfig` struct that represents the AWS secret access key to use for authentication. It can be set using the `WithSecret` function, which is an `AwsConfigOption` that sets the value of this field when passed as an @property {bool} UseS3PathStyleAddressing - `UseS3PathStyleAddressing` is a boolean field in the `AwsConfig` struct that determines whether to use path-style or virtual-hosted style addressing when making requests to Amazon S3. If it is set to `true`, path-style addressing will be used, and if it is

func NewAwsConfig

func NewAwsConfig(opts ...AwsConfigOption) (*AwsConfig, error)

NewAwsConfig creates a new AwsConfig.

func (*AwsConfig) Apply

func (cfg *AwsConfig) Apply(opts ...AwsConfigOption)

Apply applies the given AwsConfigOptions to this AwsConfig.

func (*AwsConfig) Validate

func (cfg *AwsConfig) Validate() error

Validate validates this AwsConfig.

type AwsConfigOption

type AwsConfigOption func(*AwsConfig)

AwsConfigOption is a function that configures a AwsConfig.

func WithEndpoint

func WithEndpoint(endpoint string) AwsConfigOption

WithEndpoint sets an endpoint.

func WithID

func WithID(id string) AwsConfigOption

WithID sets an ID.

func WithProfile

func WithProfile(profile string) AwsConfigOption

WithProfile sets a profile.

func WithRegion

func WithRegion(region string) AwsConfigOption

WithRegion sets a region.

func WithSecret

func WithSecret(secret string) AwsConfigOption

WithSecret sets a secret.

func WithUseS3PathStyleAddressing

func WithUseS3PathStyleAddressing(useS3PathStyleAddressing bool) AwsConfigOption

WithUseS3PathStyleAddressing sets a useS3PathStyleAddressing.

type Client

type Client struct {
	// `SqsClient sqsiface.SQSAPI` is defining a field in the `Client` struct that holds an interface for
	// the SQS API. This allows for the use of a mock SQS client for testing purposes.
	SqsClient sqsiface.SQSAPI
	// Timeout is the timeout for the client.
	// `Timeout time.Duration` is a field in the `Client` struct that holds the timeout duration for
	// operations performed by the SQS client. This timeout duration specifies the maximum amount of time
	// that the client will wait for an operation to complete before timing out.
	Timeout time.Duration
	// `ReadTimeout time.Duration` is a field in the `Client` struct that holds the timeout duration for
	// read operations performed by the SQS client. This timeout duration specifies the maximum amount of
	// time that the client will wait for a read operation to complete before timing out.
	ReadTimeout time.Duration
	// `WriteTimeout time.Duration` is a field in the `Client` struct that holds the timeout duration for
	// write operations performed by the SQS client. This timeout duration specifies the maximum amount of
	// time that the client will wait for a write operation to complete before timing out.
	WriteTimeout time.Duration
	// `Config *Config` is a field in the `Client` struct that holds the configuration for the SQS client.
	// It is used to configure various settings such as the maximum number of messages to receive,
	// the visibility timeout, and the wait time for long polling. The `Config` struct is defined
	// elsewhere in the codebase and contains fields for these settings.
	Config *Config

	// `AwsConfig    *AwsConfig` is a field in the `Client` struct that holds the AWS configuration for
	// the SQS client. It is used to configure the AWS credentials and region for the SQS client.
	AwsConfig *AwsConfig
}

The `Client` struct defines a client for interacting with the Amazon Simple Queue Service (SQS) API, with fields for the SQS API interface, timeout durations, configuration settings, and AWS credentials. @property SqsClient - a field in the `Client` struct that holds an interface for the SQS API. This allows for the use of a mock SQS client for testing purposes. @property Timeout - The timeout duration for operations performed by the SQS client. This timeout duration specifies the maximum amount of time that the client will wait for an operation to complete before timing out. @property ReadTimeout - `ReadTimeout` is a field in the `Client` struct that holds the timeout duration for read operations performed by the SQS client. This timeout duration specifies the maximum amount of time that the client will wait for a read operation to complete before timing out. @property WriteTimeout - The timeout duration for write operations performed by the SQS client. This timeout duration specifies the maximum amount of time that the client will wait for a write operation to complete before timing out. @property Config - A pointer to a struct that holds configuration settings for the SQS client, such as the maximum number of messages to receive, the visibility timeout, and the wait time for long polling. @property AwsConfig - A field in the `Client` struct that holds the AWS configuration for the SQS client. It is used to configure the AWS credentials and region for the SQS client. The `AwsConfig` struct is defined elsewhere in the codebase and contains fields for these settings.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates a new client with optional configuration options.

func (*Client) Delete

func (h *Client) Delete(ctx context.Context, queueURL, rcvHandle string) error

Delete deletes a message from a queue. It returns an error if the message could not be deleted.

func (*Client) Receive

func (h *Client) Receive(ctx context.Context, queueURL string) ([]*Message, error)

Receive receives messages from an SQS queue specified by the `queueURL` parameter. It takes a `context.Context` parameter for handling timeouts and returns a slice of `Message` pointers and an error. It uses the AWS SDK to make a `ReceiveMessageWithContext` API call to the SQS service, passing in the `queueURL` and other parameters to retrieve a single message from the queue. It then converts the received message into a `Message` struct and appends it to the `messages` slice. Finally, it returns the `messages` slice or an error if there was a problem receiving the message.

func (*Client) Send

func (h *Client) Send(ctx context.Context, req *SendRequest) (string, error)

Send sends a message to a target queue present in the request object

func (*Client) SendMessage

func (h *Client) SendMessage(ctx context.Context, msg *sqs.SendMessageInput) (*string, error)

SendMessage sends a message to a queue.

func (*Client) Validate

func (c *Client) Validate() error

Validate validates the client

type Config

type Config struct {
	// The maximum number of messages to return. Amazon SQS never returns
	// more messages than this value (however, fewer messages might be returned).
	// Valid values: 1 to 10. Default: 1.
	MaxNumberOfMessages *int
	// The duration (in seconds) that the received messages are hidden from subsequent
	// retrieve requests after being retrieved by a ReceiveMessage request.
	MaxWaitTimeInSeconds *time.Duration
	// A list of attributes that need to be returned along with each message.
	Attributes *[]string
}

The Config type defines parameters for receiving messages from Amazon SQS. @property MaxNumberOfMessages - This property specifies the maximum number of messages that can be returned by an Amazon SQS (Simple Queue Service) request. The value can range from 1 to 10, and the default value is 1. @property MaxWaitTimeInSeconds - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request. This means that if a message is retrieved by a ReceiveMessage request, it will not be visible to other requests for the duration specified in this property. After the duration has elapsed @property Attributes - A list of attributes that need to be returned along with each message. These attributes provide additional information about the message, such as its unique identifier, timestamp, and message body. The list of available attributes includes MessageId, ReceiptHandle, MD5OfBody, Body, and others. By default,

func NewConfigOptions

func NewConfigOptions(opts ...ConfigOption) *Config

NewConfigOptions returns a new Config with the given options

type ConfigOption

type ConfigOption func(*Config)

ConfigOption is a function that sets a configuration option such as MaxNumberOfMessages

func WithAttributes

func WithAttributes(attributes []string) ConfigOption

WithAttributes sets the Attributes configuration option

func WithMaxNumberOfMessages

func WithMaxNumberOfMessages(maxNumberOfMessages int) ConfigOption

WithMaxNumberOfMessages sets the MaxNumberOfMessages configuration option

func WithMaxWaitTimeSeconds

func WithMaxWaitTimeSeconds(MaxWaitTimeInSeconds time.Duration) ConfigOption

WithMaxWaitTimeSeconds sets the MaxWaitTimeSeconds configuration option

type Message

type Message struct {
	// The `ID` field is defining a string property named `ID` for the `Message` struct. This property
	// represents the unique identifier for the message.
	ID string
	// The `ReceiptHandle` field in the `Message` struct is defining a string property named
	// `ReceiptHandle` that represents a unique identifier for a message that has been received from an
	// Amazon Simple Queue Service (SQS) queue. It is used to acknowledge the receipt of a message and to
	// delete it from the queue.
	ReceiptHandle string
	// The `Body` field is defining a string property named `Body` for the `Message` struct. This property
	// represents the message body, which contains the content of the message being sent or received.
	Body string
	// The `Attributes` field in the `Message` struct is defining a map of key-value pairs that provide
	// additional information about the message. These attributes can include metadata such as message
	// timestamps, message grouping IDs, and message deduplication IDs. The specific attributes available
	// depend on the messaging service being used. The `map[string]string` type indicates that the keys and
	// values in the map are both strings.
	Attributes map[string]string
}

The above code defines a Go struct type called "Message" with four fields: ID, ReceiptHandle, Body, and Attributes. @property {string} ID - The unique identifier for the message. @property {string} ReceiptHandle - ReceiptHandle is a unique identifier for a message that has been received from an Amazon Simple Queue Service (SQS) queue. It is used to acknowledge the receipt of a message and to delete it from the queue. @property {string} Body - The message body, which contains the content of the message being sent or received. @property Attributes - Attributes is a map of key-value pairs that provide additional information about the message. These attributes can include metadata such as message timestamps, message grouping IDs, and message deduplication IDs. The specific attributes available depend on the messaging service being used.

type MessageClientInterface

type MessageClientInterface interface {
	// The `Send` method is used to send a message to an SQS queue. It takes a context and a `SendRequest`
	// struct as input, and returns a string and an error. The string returned is the message ID of the
	// sent message, and the error returned indicates whether there was an error sending the message.
	Send(ctx context.Context, req *SendRequest) (string, error)
	// The `SendMessage` method is used to send a message to an SQS queue using the `sqs.SendMessageInput`
	// struct as input. It takes a context and a `SendMessageInput` struct as input, and returns a string
	// and an error. The string returned is the message ID of the sent message, and the error returned
	// indicates whether there was an error sending the message.
	SendMessage(ctx context.Context, msg *sqs.SendMessageInput) (*string, error)
	// The `Receive` method is used to receive messages from an SQS queue. It takes a context and a queue
	// URL as input, and returns a slice of `Message` structs and an error. The `Message` struct contains
	// information about the received message, such as the message ID, receipt handle, and message body.
	// The error returned indicates whether there was an error receiving the messages.
	Receive(ctx context.Context, queueURL string) ([]*Message, error)
	// The `Delete` method is used to delete a message from an SQS queue. It takes a context, a queue URL,
	// and a receipt handle as input, and returns an error indicating whether there was an error deleting
	// the message. The receipt handle is a unique identifier for the message that was received from the
	// queue, and is used to identify the message to be deleted.
	Delete(ctx context.Context, queueURL, rcvHandle string) error
}

The MessageClientInterface is an interface that defines methods for sending, receiving, and deleting messages from an SQS queue. @property Send - A method that sends a message to an SQS queue. It takes a context and a `SendRequest` struct as input, and returns a string and an error. The string returned is the message ID of the sent message, and the error returned indicates whether there was an error sending the message. @property SendMessage - A method of the MessageClientInterface that is used to send a message to an SQS queue using the `sqs.SendMessageInput` struct as input. It takes a context and a `SendMessageInput` struct as input, and returns a string and an error. The string returned is the message ID @property Receive - A method of the MessageClientInterface interface that is used to receive messages from an SQS queue. It takes a context and a queue URL as input, and returns a slice of `Message` structs and an error. The `Message` struct contains information about the received message, such as the message @property {error} Delete - The `Delete` method is used to delete a message from an SQS queue. It takes a context, a queue URL, and a receipt handle as input, and returns an error indicating whether there was an error deleting the message. The receipt handle is a unique identifier for the message that was received

func NewMockClient

func NewMockClient() (MessageClientInterface, error)

type MockClient

type MockClient struct{}

func (*MockClient) Delete

func (*MockClient) Delete(ctx context.Context, queueURL string, rcvHandle string) error

Delete implements MessageClientInterface.

func (*MockClient) Receive

func (*MockClient) Receive(ctx context.Context, queueURL string) ([]*Message, error)

Receive implements MessageClientInterface.

func (*MockClient) Send

func (*MockClient) Send(ctx context.Context, req *SendRequest) (string, error)

Send implements MessageClientInterface.

func (*MockClient) SendMessage

func (*MockClient) SendMessage(ctx context.Context, msg *sqs.SendMessageInput) (*string, error)

SendMessage implements MessageClientInterface.

type Option

type Option func(*Client)

Option is a function that configures the client.

func WithAwsConfig

func WithAwsConfig(config *AwsConfig) Option

WithAwsConfig sets the aws config for the client

func WithConfig

func WithConfig(config *Config) Option

WithConfig sets the Config for the client

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) Option

WithReadTimeout sets the read timeout for the client

func WithSqsClient

func WithSqsClient(client sqsiface.SQSAPI) Option

WithClient sets the client for the client

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for the client

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) Option

WithWriteTimeout sets the write timeout for the client

type SendRequest

type SendRequest struct {
	// `QueueURL string` is defining a string property named `QueueURL` for the `SendRequest` struct. This
	// property represents the URL of the Amazon SQS queue to which the message will be sent.
	QueueURL string
	// The `Body` property is defining a string property named `Body` for the `SendRequest` struct. This
	// property represents the message body that will be sent to the specified queue.
	Body string
	// The `Attributes []Attribute` field in the `SendRequest` struct is defining a slice of `Attribute`
	// structs that can be used to add custom metadata to the message being sent to the queue. These
	// attributes can be used to provide additional information about the message, such as message type,
	// priority, or any other relevant information. The `Attribute` struct typically contains a `Key` and a
	// `Value`, and an optional `Type` field.
	Attributes []Attribute
}

The SendRequest type represents a message to be sent to a queue with a specified URL, body, and attributes. @property {string} QueueURL - QueueURL is a string property that represents the URL of the Amazon SQS queue to which the message will be sent. @property {string} Body - The message body that will be sent to the specified queue. @property {[]Attribute} Attributes - Attributes is a slice of Attribute structs that can be used to add custom metadata to the message being sent to the queue. These attributes can be used to provide additional information about the message, such as message type, priority, or any other relevant information. The Attribute struct typically contains a Name and a Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL