Skip to content

Commit

Permalink
1. Added linter
Browse files Browse the repository at this point in the history
2. Fixed per linting recommendations
  • Loading branch information
stewartboyd119 committed Jul 23, 2024
1 parent 5f0a6be commit a6f1362
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 11 deletions.
69 changes: 69 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
run:
skip-dirs:
- docs
- datadog
- kustomize
skip-files:
- 'wire_gen.go'
tests: false
linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
gci:
sections:
- standard
- default
gosimple:
go: '1.17'
govet:
check-shadowing: true
settings:
printf:
funcs:
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Debug
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Info
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Warn
- (gitlab.zgtools.net/devex/archetypes/gomods/zlog.Logger).Error
depguard:
rules:
Main:
files:
- $all
- "!$test"
deny:
- github.com/satori/go.uuid: Prefer "github.com/google/uuid"
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- cyclop
- decorder
- depguard
- deadcode
- dupl
- errcheck
- errchkjson
- errname
- errorlint
- exportloopref
- gci
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- gosimple
- govet
- ineffassign
- nolintlint
- prealloc
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Directories containing independent Go modules.
MODULE_DIRS = .

.PHONY: test-no-setup
test-no-setup:
./coverage.sh
Expand All @@ -20,4 +23,14 @@ example-producer:

.PHONY: example-worker
example-worker:
go run example/worker/worker.go
go run example/worker/worker.go

.PHONY: lint
lint: golangci-lint

.PHONY: golangci-lint
golangci-lint:
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
echo "[lint] golangci-lint: $(mod)" && \
golangci-lint run --path-prefix $(mod) ./...) &&) true
13 changes: 6 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,16 @@ func (c *Client) Writer(_ context.Context, topicConfig ProducerTopicConfig, opts
}

func getFormatter(topicConfig TopicConfig) (zfmt.Formatter, error) {
var fmtter zfmt.Formatter
switch topicConfig.GetFormatter() {
case CustomFmt:
fmtter = &noopFormatter{}
return &noopFormatter{}, nil
default:
fmtter, _ = zfmt.GetFormatter(topicConfig.GetFormatter(), topicConfig.GetSchemaID())
}
if fmtter == nil {
return nil, fmt.Errorf("unsupported formatter %s", topicConfig.GetFormatter())
f, err := zfmt.GetFormatter(topicConfig.GetFormatter(), topicConfig.GetSchemaID())
if err != nil {
return nil, fmt.Errorf("unsupported formatter %s", topicConfig.GetFormatter())
}
return f, nil
}
return fmtter, nil
}

// Close terminates all cached readers and writers gracefully.
Expand Down
4 changes: 3 additions & 1 deletion example/worker/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func main() {
)
ctx, c := context.WithTimeout(context.Background(), 2*time.Minute)
defer c()
w.Run(ctx, nil)
if err := w.Run(ctx, nil); err != nil {
log.Panic(err)
}
}

type kafkaProcessorError struct{}
Expand Down
4 changes: 3 additions & 1 deletion example/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func main() {
// Register a processor which is executed per message.
// Speedup is used to create multiple processor goroutines. Order is still maintained with this setup by way of `virtual partitions`
work := wf.Create(topicConfig, &Processor{}, zkafka.Speedup(5))
work.Run(ctx, shutdown)
if err := work.Run(ctx, shutdown); err != nil {
log.Panic(err)
}
}

type Processor struct{}
Expand Down
1 change: 1 addition & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func makeProducerMessageRaw(_ context.Context, serviceName, topic string, key *s
Key: obsKeyOriginService,
Value: []byte(serviceName),
})
//nolint:errcheck // Its not particularly noteworthy if if host isn't propagated forward. We'll suppress the error
hostname, _ := os.Hostname()
// hn is empty string if there's an error
kafkaMessage.Headers = append(kafkaMessage.Headers, kafka.Header{
Expand Down
6 changes: 5 additions & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ func (w *KWriter) WriteRaw(ctx context.Context, key *string, value []byte, opts
e := <-deliveryChan

w.lifecyclePostAck(ctx, begin)
m := e.(*kafka.Message)

m, ok := e.(*kafka.Message)
if !ok {
return Response{}, errors.New("unexpected message delivered on kafka delivery channel")
}

span.SetAttributes(
semconv.MessagingMessageIDKey.Int64(int64(m.TopicPartition.Offset)),
Expand Down

0 comments on commit a6f1362

Please sign in to comment.