Skip to content

Commit 961c620

Browse files
authored
Merge pull request zeromicro#53 from algobot76/document-pusher
doc: add missing comments in pusher.go
2 parents f2bc42e + 48c26db commit 961c620

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kq/pusher.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type (
2525
}
2626
)
2727

28+
// NewPusher returns a Pusher with the given Kafka addresses and topic.
2829
func NewPusher(addrs []string, topic string, opts ...PushOption) *Pusher {
2930
producer := &kafka.Writer{
3031
Addr: kafka.TCP(addrs...),
@@ -49,6 +50,7 @@ func NewPusher(addrs []string, topic string, opts ...PushOption) *Pusher {
4950
return pusher
5051
}
5152

53+
// Close closes the Pusher and releases any resources used by it.
5254
func (p *Pusher) Close() error {
5355
if p.executor != nil {
5456
p.executor.Flush()
@@ -57,13 +59,15 @@ func (p *Pusher) Close() error {
5759
return p.producer.Close()
5860
}
5961

62+
// Name returns the name of the Kafka topic that the Pusher is sending messages to.
6063
func (p *Pusher) Name() string {
6164
return p.topic
6265
}
6366

67+
// Push sends a message to the Kafka topic.
6468
func (p *Pusher) Push(v string) error {
6569
msg := kafka.Message{
66-
Key: []byte(strconv.FormatInt(time.Now().UnixNano(), 10)),
70+
Key: []byte(strconv.FormatInt(time.Now().UnixNano(), 10)), // current timestamp
6771
Value: []byte(v),
6872
}
6973
if p.executor != nil {
@@ -73,12 +77,14 @@ func (p *Pusher) Push(v string) error {
7377
}
7478
}
7579

80+
// WithChunkSize customizes the Pusher with the given chunk size.
7681
func WithChunkSize(chunkSize int) PushOption {
7782
return func(options *chunkOptions) {
7883
options.chunkSize = chunkSize
7984
}
8085
}
8186

87+
// WithFlushInterval customizes the Pusher with the given flush interval.
8288
func WithFlushInterval(interval time.Duration) PushOption {
8389
return func(options *chunkOptions) {
8490
options.flushInterval = interval

0 commit comments

Comments
 (0)