Skip to content

Commit d9440b9

Browse files
committed
docs: write godocs in Producer
1 parent 0878d4a commit d9440b9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

producer.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@ import (
66
"github.com/google/uuid"
77
)
88

9+
// ProducerOptions holds configuration options for a Producer.
910
type ProducerOptions struct {
11+
// IDGenerator is function that generates a unique identifier for each message produced by the Producer.
12+
// The default ID generator is uuid.NewString.
1013
IDGenerator func() string
1114
}
1215

16+
// WithIDGenerator is an option function to set a custom ID generator for the Producer.
17+
// Use this function to provide a custom function that generates unique identifiers for messages.
18+
// The default ID generator is uuid.NewString.
1319
func WithIDGenerator(idGenerator func() string) func(o *ProducerOptions) {
1420
return func(o *ProducerOptions) {
1521
o.IDGenerator = idGenerator
1622
}
1723
}
1824

25+
// NewProducer creates a new instance of a Producer, which is used to produce messages to a DynamoDB-based queue.
26+
// The Producer can be configured with various options, such as a custom ID generator.
1927
func NewProducer[T any](client Client[T], opts ...func(o *ProducerOptions)) *Producer[T] {
2028
o := &ProducerOptions{
2129
IDGenerator: uuid.NewString,
@@ -29,20 +37,29 @@ func NewProducer[T any](client Client[T], opts ...func(o *ProducerOptions)) *Pro
2937
}
3038
}
3139

40+
// Producer is a generic struct responsible for producing messages of any type T to a DynamoDB-based queue.
3241
type Producer[T any] struct {
3342
client Client[T]
3443
idGenerator func() string
3544
}
3645

46+
// ProduceInput represents the input parameters for producing a message.
3747
type ProduceInput[T any] struct {
38-
Data T
48+
// Data is the content of the message to be produced. The type T allows for flexibility in the data type of the message payload.
49+
Data T
50+
// DelaySeconds is the delay time (in seconds) before the message is sent to the queue.
3951
DelaySeconds int
4052
}
4153

54+
// ProduceOutput represents the result of the produce operation.
4255
type ProduceOutput[T any] struct {
56+
// Message is a pointer to the Message type containing information about the produced message.
4357
Message *Message[T]
4458
}
4559

60+
// Produce sends a message to the queue using the provided input parameters.
61+
// It generates a unique ID for the message using the Producer's ID generator and delegates to the Client's SendMessage method.
62+
// An error is returned if the SendMessage operation fails.
4663
func (c *Producer[T]) Produce(ctx context.Context, params *ProduceInput[T]) (*ProduceOutput[T], error) {
4764
if params == nil {
4865
params = &ProduceInput[T]{}

0 commit comments

Comments
 (0)