Search code examples
goapache-kafkasarama

Error installing golang Shopify/sarama Kafka library


Getting following error when installing golang github.com/Shopify/sarama kafka library

go get github.com/Shopify/sarama

# github.com/Shopify/sarama
go/src/github.com/Shopify/sarama/config.go:678:37: undefined: io.Discard
go/src/github.com/Shopify/sarama/decompress.go:43:10: undefined: io.ReadAll
go/src/github.com/Shopify/sarama/decompress.go:55:10: undefined: io.ReadAll
go/src/github.com/Shopify/sarama/sarama.go:89:29: undefined: io.Discard

Solution

  • ioutil.Discard and ioutil.ReadAll has moved to io.Discard and io.ReadAll respectively as of Go 1.16, You should use Go 1.16 or use an older version of sarama (I think v1.20.1 should work for go1.13)

    Also from sarama's README:

    Sarama provides a "2 releases + 2 months" compatibility guarantee: we support the two latest stable releases of Kafka and Go, and we provide a two month grace period for older releases. This means we currently officially support Go 1.15 through 1.16, and Kafka 2.7 through 2.8, although older releases are still likely to work.