From d0919c3abf21087332a1886bfdc32865b0ae5bf6 Mon Sep 17 00:00:00 2001 From: syumai Date: Sun, 10 Nov 2024 00:30:01 +0900 Subject: [PATCH] add comments to queues public funcs --- cloudflare/queues/batchmessage.go | 4 ++++ cloudflare/queues/producer.go | 29 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cloudflare/queues/batchmessage.go b/cloudflare/queues/batchmessage.go index 7258129..c54ba3c 100644 --- a/cloudflare/queues/batchmessage.go +++ b/cloudflare/queues/batchmessage.go @@ -11,18 +11,22 @@ type BatchMessage struct { options *sendOptions } +// NewTextBatchMessage creates a single text message to be batched before sending to a queue. func NewTextBatchMessage(content string, opts ...SendOption) *BatchMessage { return newBatchMessage(js.ValueOf(content), contentTypeText, opts...) } +// NewBytesBatchMessage creates a single byte array message to be batched before sending to a queue. func NewBytesBatchMessage(content []byte, opts ...SendOption) *BatchMessage { return newBatchMessage(js.ValueOf(content), contentTypeBytes, opts...) } +// NewJSONBatchMessage creates a single JSON message to be batched before sending to a queue. func NewJSONBatchMessage(content any, opts ...SendOption) *BatchMessage { return newBatchMessage(js.ValueOf(content), contentTypeJSON, opts...) } +// NewV8BatchMessage creates a single raw JS value message to be batched before sending to a queue. func NewV8BatchMessage(content js.Value, opts ...SendOption) *BatchMessage { return newBatchMessage(content, contentTypeV8, opts...) } diff --git a/cloudflare/queues/producer.go b/cloudflare/queues/producer.go index 3c0dd6c..6ebf3b6 100644 --- a/cloudflare/queues/producer.go +++ b/cloudflare/queues/producer.go @@ -25,29 +25,32 @@ func NewProducer(queueName string) (*Producer, error) { return &Producer{queue: inst}, nil } -func (p *Producer) SendText(content string, opts ...SendOption) error { - return p.send(js.ValueOf(content), contentTypeText, opts...) +// SendText sends a single text message to a queue. +func (p *Producer) SendText(body string, opts ...SendOption) error { + return p.send(js.ValueOf(body), contentTypeText, opts...) } -func (p *Producer) SendBytes(content []byte, opts ...SendOption) error { - ua := jsutil.NewUint8Array(len(content)) - js.CopyBytesToJS(ua, content) +// SendBytes sends a single byte array message to a queue. +func (p *Producer) SendBytes(body []byte, opts ...SendOption) error { + ua := jsutil.NewUint8Array(len(body)) + js.CopyBytesToJS(ua, body) // accortind to docs, "bytes" type requires an ArrayBuffer to be sent, however practical experience shows that ArrayBufferView should // be used instead and with Uint8Array.buffer as a value, the send simply fails return p.send(ua, contentTypeBytes, opts...) } -func (p *Producer) SendJSON(content any, opts ...SendOption) error { - return p.send(js.ValueOf(content), contentTypeJSON, opts...) +// SendJSON sends a single JSON message to a queue. +func (p *Producer) SendJSON(body any, opts ...SendOption) error { + return p.send(js.ValueOf(body), contentTypeJSON, opts...) } -func (p *Producer) SendV8(content js.Value, opts ...SendOption) error { - return p.send(content, contentTypeV8, opts...) +// SendV8 sends a single raw JS value message to a queue. +func (p *Producer) SendV8(body js.Value, opts ...SendOption) error { + return p.send(body, contentTypeV8, opts...) } -// send sends a single message to a queue. This function allows setting send options for the message. -// If no options are provided, the default options are used (QueueContentTypeJSON and no delay). -// +// send sends a single message to a queue. +// This function allows setting send options for the message. // - https://developers.cloudflare.com/queues/configuration/javascript-apis/#producer // - https://developers.cloudflare.com/queues/configuration/javascript-apis/#queuesendoptions func (p *Producer) send(body js.Value, contentType contentType, opts ...SendOption) error { @@ -63,7 +66,7 @@ func (p *Producer) send(body js.Value, contentType contentType, opts ...SendOpti return err } -// SendBatch sends multiple messages to a queue. This function allows setting options for each message. +// SendBatch sends multiple messages to a queue. This function allows setting options for each message. func (p *Producer) SendBatch(messages []*BatchMessage, opts ...BatchSendOption) error { var options batchSendOptions for _, opt := range opts {