Skip to content

Commit

Permalink
Added kafka.Opt type (func(*kafka.Client))
Browse files Browse the repository at this point in the history
  • Loading branch information
cswank committed Oct 8, 2019
1 parent 755cdac commit 8d5ba14
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ type Message struct {
Offset int64 `json:"offset"`
}

type Opt func(*Client)

//New returns a kafka Client.
func New(addrs []string, opts ...func(*Client)) (*Client, error) {
func New(addrs []string, opts ...Opt) (*Client, error) {
cfg, err := getConfig()
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func main() {
}

func connect() *kafka.Client {
var opts []func(*kafka.Client)
var opts []kafka.Opt
if *decoder != "" {
dec := getDecoder(*decoder)
opts = []func(*kafka.Client){kafka.WithDecoder(dec)}
opts = []kafka.Opt{kafka.WithDecoder(dec)}
}

cli, err := kafka.New(getAddresses(*addrs), opts...)
Expand Down

0 comments on commit 8d5ba14

Please sign in to comment.