Skip to content

Commit

Permalink
fix golint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CanerPatir committed Dec 30, 2022
1 parent a698e5c commit 1d3a9a0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion json_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package godcpkafkaconnector

import "github.com/json-iterator/go"

var JsonIter = jsoniter.ConfigFastest
var JSONIter = jsoniter.ConfigFastest
5 changes: 3 additions & 2 deletions kafka/producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
}

Expand Down
19 changes: 12 additions & 7 deletions kafka/producer/producerbatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...) }

0 comments on commit 1d3a9a0

Please sign in to comment.