github.com/QuangHoangHao/kafka-go@v0.4.36/commit.go (about)

     1  package kafka
     2  
     3  // A commit represents the instruction of publishing an update of the last
     4  // offset read by a program for a topic and partition.
     5  type commit struct {
     6  	topic     string
     7  	partition int
     8  	offset    int64
     9  }
    10  
    11  // makeCommit builds a commit value from a message, the resulting commit takes
    12  // its topic, partition, and offset from the message.
    13  func makeCommit(msg Message) commit {
    14  	return commit{
    15  		topic:     msg.Topic,
    16  		partition: msg.Partition,
    17  		offset:    msg.Offset + 1,
    18  	}
    19  }
    20  
    21  // makeCommits generates a slice of commits from a list of messages, it extracts
    22  // the topic, partition, and offset of each message and builds the corresponding
    23  // commit slice.
    24  func makeCommits(msgs ...Message) []commit {
    25  	commits := make([]commit, len(msgs))
    26  
    27  	for i, m := range msgs {
    28  		commits[i] = makeCommit(m)
    29  	}
    30  
    31  	return commits
    32  }
    33  
    34  // commitRequest is the data type exchanged between the CommitMessages method
    35  // and internals of the reader's implementation.
    36  type commitRequest struct {
    37  	commits []commit
    38  	errch   chan<- error
    39  }