From 1d3a9a0e7a6c1666ece7551a726b35f29fbfbdce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caner=20Pat=C4=B1r?= Date: Fri, 30 Dec 2022 13:51:29 +0300 Subject: [PATCH] fix golint issues --- config/config.go | 6 +++--- connector.go | 4 ++-- json_config.go | 2 +- kafka/producer/producer.go | 5 +++-- kafka/producer/producerbatch.go | 19 ++++++++++++------- logger/logger.go | 4 ++-- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index fd39a59..807ee8f 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,11 @@ package config import ( - "github.com/gookit/config/v2" - "github.com/gookit/config/v2/yamlv3" "godcpkafkaconnector/logger" "time" + + "github.com/gookit/config/v2" + "github.com/gookit/config/v2/yamlv3" ) type Kafka struct { @@ -31,7 +32,6 @@ func NewConfig(name string, filePath string, errorLogger logger.Logger) *Config conf := config.New(name).WithOptions(Options).WithDriver(yamlv3.Driver) err := conf.LoadFiles(filePath) - if err != nil { errorLogger.Printf("Error while reading config %v", err) } diff --git a/connector.go b/connector.go index d0ae83c..c717325 100644 --- a/connector.go +++ b/connector.go @@ -2,11 +2,12 @@ package godcpkafkaconnector import ( "context" - godcpclient "github.com/Trendyol/go-dcp-client" "godcpkafkaconnector/config" "godcpkafkaconnector/couchbase" kafka "godcpkafkaconnector/kafka/producer" "godcpkafkaconnector/logger" + + godcpclient "github.com/Trendyol/go-dcp-client" ) type Connector interface { @@ -61,7 +62,6 @@ func (c *connector) listener(event interface{}, err error) { c.errorLogger.Printf("error | %v", err) } } - } func NewConnector(configPath string, mapper Mapper) Connector { diff --git a/json_config.go b/json_config.go index 772f784..ce02e90 100644 --- a/json_config.go +++ b/json_config.go @@ -2,4 +2,4 @@ package godcpkafkaconnector import "github.com/json-iterator/go" -var JsonIter = jsoniter.ConfigFastest +var JSONIter = jsoniter.ConfigFastest diff --git a/kafka/producer/producer.go b/kafka/producer/producer.go index 9f2cfb4..6a2942f 100644 --- a/kafka/producer/producer.go +++ b/kafka/producer/producer.go @@ -2,12 +2,13 @@ package kafka import ( "context" - "github.com/segmentio/kafka-go" "godcpkafkaconnector/config" "godcpkafkaconnector/logger" "math" "strings" "time" + + "github.com/segmentio/kafka-go" ) type Producer interface { @@ -32,7 +33,7 @@ func NewProducer(config *config.Kafka, logger logger.Logger, errorLogger logger. ErrorLogger: errorLogger, } return &producer{ - producerBatch: NewProducerBatch(config.ProducerBatchTickerDuration, writer, config.ProducerBatchSize, logger, errorLogger), + producerBatch: newProducerBatch(config.ProducerBatchTickerDuration, writer, config.ProducerBatchSize, logger, errorLogger), } } diff --git a/kafka/producer/producerbatch.go b/kafka/producer/producerbatch.go index 905e60c..5f8e87c 100644 --- a/kafka/producer/producerbatch.go +++ b/kafka/producer/producerbatch.go @@ -2,10 +2,11 @@ package kafka import ( "context" - "github.com/segmentio/kafka-go" "godcpkafkaconnector/logger" "sync" "time" + + "github.com/segmentio/kafka-go" ) type producerBatch struct { @@ -20,7 +21,13 @@ type producerBatch struct { errorLogger logger.Logger } -func NewProducerBatch(batchTime time.Duration, writer *kafka.Writer, batchLimit int, logger logger.Logger, errorLogger logger.Logger) *producerBatch { +func newProducerBatch( + batchTime time.Duration, + writer *kafka.Writer, + batchLimit int, + logger logger.Logger, + errorLogger logger.Logger, +) *producerBatch { batch := &producerBatch{ batchTickerDuration: batchTime, batchTicker: time.NewTicker(batchTime), @@ -34,11 +41,9 @@ func NewProducerBatch(batchTime time.Duration, writer *kafka.Writer, batchLimit go func() { errChan := make(chan error, 1) batch.CheckBatchTicker(errChan) - for { - select { - case err := <-errChan: - errorLogger.Printf("Batch producer flush error %v", err) - } + + for err := range errChan { + errorLogger.Printf("Batch producer flush error %v", err) } }() return batch diff --git a/logger/logger.go b/logger/logger.go index 1f9ba21..9110622 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -15,6 +15,6 @@ func (d *DefaultLogger) Printf(msg string, args ...interface{}) { var Log = DefaultLogger{} -type LoggerFunc func(string, ...interface{}) +type LogFunc func(string, ...interface{}) -func (f LoggerFunc) Printf(msg string, args ...interface{}) { f(msg, args...) } +func (f LogFunc) Printf(msg string, args ...interface{}) { f(msg, args...) }