Skip to content

Commit

Permalink
breaking: rename CommitCallback to AutoCommitCallback
Browse files Browse the repository at this point in the history
This is more accurate to the exact purpose of the callback: it is *only*
used when autocommitting.
  • Loading branch information
twmb committed Sep 1, 2021
1 parent ac9fd1c commit 525b2d2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/kgo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,12 @@ func (cfg *cfg) validate() error {
if cfg.autocommitGreedy && cfg.autocommitMarks {
return errors.New("cannot enable both greedy autocommitting and marked autocommitting")
}
if cfg.autocommitGreedy || cfg.autocommitDisable || cfg.autocommitMarks && len(cfg.group) == 0 {
if (cfg.autocommitGreedy || cfg.autocommitDisable || cfg.autocommitMarks || cfg.setCommitCallback) && len(cfg.group) == 0 {
return errors.New("invalid autocommit options specified when a group was not specified")
}
if (cfg.setLost || cfg.setRevoked || cfg.setAssigned) && len(cfg.group) == 0 {
return errors.New("invalid group partition assigned/revoked/lost functions set when a group was not specified")
}

return nil
}
Expand Down Expand Up @@ -1389,8 +1392,8 @@ func GroupProtocol(protocol string) GroupOpt {
return groupOpt{func(cfg *cfg) { cfg.protocol = protocol }}
}

// CommitCallback sets the callback to use if autocommitting is enabled. This
// overrides the default callback that logs errors and continues.
func CommitCallback(fn func(*Client, *kmsg.OffsetCommitRequest, *kmsg.OffsetCommitResponse, error)) GroupOpt {
// AutoCommitCallback sets the callback to use if autocommitting is enabled.
// This overrides the default callback that logs errors and continues.
func AutoCommitCallback(fn func(*Client, *kmsg.OffsetCommitRequest, *kmsg.OffsetCommitResponse, error)) GroupOpt {
return groupOpt{func(cfg *cfg) { cfg.commitCallback, cfg.setCommitCallback = fn, true }}
}

0 comments on commit 525b2d2

Please sign in to comment.