Skip to content

Commit 08716e2

Browse files
authored
fix: documentation and utilities (#28)
1 parent 544e1e9 commit 08716e2

File tree

25 files changed

+511
-261
lines changed

25 files changed

+511
-261
lines changed

.golangci.yaml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.golangci.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# This configuration file is not a recommendation.
2+
#
3+
# We intentionally use a limited set of linters.
4+
# This configuration file is used with different version of golangci-lint to avoid regressions:
5+
# the linters can change between version,
6+
# their configuration may be not compatible or their reports can be different,
7+
# and this can break some of our tests.
8+
# Also, some linters are not relevant for the project (e.g. linters related to SQL).
9+
#
10+
# We have specific constraints, so we use a specific configuration.
11+
#
12+
# See the file `.golangci.reference.yml` to have a list of all available configuration options.
13+
14+
version: "2"
15+
16+
linters:
17+
default: none
18+
# This list of linters is not a recommendation (same thing for all this configuration file).
19+
# We intentionally use a limited set of linters.
20+
# See the comment on top of this file.
21+
enable:
22+
- bodyclose
23+
- copyloopvar
24+
- depguard
25+
- dogsled
26+
- dupl
27+
- errcheck
28+
- errorlint
29+
- funlen
30+
- gocheckcompilerdirectives
31+
- gochecknoinits
32+
- goconst
33+
- gocritic
34+
- gocyclo
35+
- godox
36+
- mnd
37+
- goprintffuncname
38+
- gosec
39+
- govet
40+
- intrange
41+
- ineffassign
42+
- lll
43+
- misspell
44+
- nakedret
45+
- noctx
46+
- nolintlint
47+
- revive
48+
- staticcheck
49+
- testifylint
50+
- unconvert
51+
- unparam
52+
- unused
53+
- whitespace
54+
55+
settings:
56+
depguard:
57+
rules:
58+
logger:
59+
deny:
60+
# logging is allowed only by logutils.Log,
61+
- pkg: "github.com/sirupsen/logrus"
62+
desc: logging is allowed only by logutils.Log.
63+
- pkg: "github.com/pkg/errors"
64+
desc: Should be replaced by standard lib errors package.
65+
- pkg: "github.com/instana/testify"
66+
desc: It's a fork of github.com/stretchr/testify.
67+
dupl:
68+
threshold: 100
69+
funlen:
70+
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
71+
statements: 50
72+
goconst:
73+
min-len: 2
74+
min-occurrences: 3
75+
gocritic:
76+
settings:
77+
hugeParam:
78+
sizeThreshold: 300
79+
enabled-tags:
80+
- diagnostic
81+
- experimental
82+
- opinionated
83+
- performance
84+
- style
85+
disabled-checks:
86+
- dupImport # https://github.com/go-critic/go-critic/issues/845
87+
- ifElseChain
88+
- octalLiteral
89+
- whyNoLint
90+
gocyclo:
91+
min-complexity: 15
92+
godox:
93+
keywords:
94+
- FIXME
95+
mnd:
96+
# don't include the "operation" and "assign"
97+
checks:
98+
- argument
99+
- case
100+
- condition
101+
- return
102+
ignored-numbers:
103+
- "0"
104+
- "1"
105+
- "2"
106+
- "3"
107+
ignored-functions:
108+
- strings.SplitN
109+
govet:
110+
settings:
111+
printf:
112+
funcs:
113+
- (github.com/rs/zerolog/log).Infof
114+
- (github.com/rs/zerolog/log).Warnf
115+
- (github.com/rs/zerolog/log).Errorf
116+
- (github.com/rs/zerolog/log).Fatalf
117+
enable:
118+
- nilness
119+
- shadow
120+
errorlint:
121+
asserts: false
122+
lll:
123+
line-length: 140
124+
misspell:
125+
locale: US
126+
ignore-rules:
127+
- "importas" # linter name
128+
nolintlint:
129+
allow-unused: false # report any unused nolint directives
130+
require-explanation: true # require an explanation for nolint directives
131+
require-specific: true # require nolint directives to be specific about which linter is being skipped
132+
revive:
133+
rules:
134+
- name: indent-error-flow
135+
- name: unexported-return
136+
disabled: true
137+
- name: unused-parameter
138+
- name: unused-receiver
139+
140+
exclusions:
141+
# presets:
142+
# - comments
143+
# - std-error-handling
144+
# - common-false-positives
145+
# - legacy
146+
paths:
147+
- misc/
148+
- examples/
149+
rules:
150+
- path: (.+)_test\.go
151+
linters:
152+
- dupl
153+
- mnd
154+
- lll
155+
- testifylint
156+
157+
formatters:
158+
enable:
159+
- gofmt
160+
- goimports
161+
settings:
162+
gofmt:
163+
rewrite-rules:
164+
- pattern: "interface{}"
165+
replacement: "any"
166+
goimports:
167+
local-prefixes:
168+
- github.com/bxcodec/goqueue
169+
exclusions:
170+
paths:
171+
- misc/

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ run-tests: $(GOTESTSUM)
3535
test: run-tests $(TPARSE) ## Run Tests & parse details
3636
@cat gotestsum.json.out | $(TPARSE) -all -notests
3737
docker-test:
38-
@docker-compose -f test.compose.yaml up -d --build
38+
@docker compose -f test.compose.yaml up -d --build
3939

4040
integration-test: docker-test
4141
@echo "Running Integration Tests"
@@ -48,12 +48,12 @@ integration-test-ci: $(GOTESTSUM) $(TPARSE)
4848
@cat gotestsum.json.out | $(TPARSE) -all -notests
4949

5050
docker-clean:
51-
@docker-compose -f test.compose.yaml down
51+
@docker compose -f test.compose.yaml down
5252

5353
lint: $(GOLANGCI) ## Runs golangci-lint with predefined configuration
5454
@echo "Applying linter"
5555
golangci-lint version
56-
golangci-lint run -c .golangci.yaml ./...
56+
golangci-lint run -c .golangci.yml ./...
5757

5858
.PHONY: lint lint-prepare clean build unittest
5959

consumer/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package consumer
33
import (
44
"github.com/bxcodec/goqueue/internal/consumer"
55
"github.com/bxcodec/goqueue/internal/consumer/rabbitmq"
6+
_ "github.com/bxcodec/goqueue/internal/shared" // Auto-setup logging
67
"github.com/bxcodec/goqueue/options"
78
consumerOpts "github.com/bxcodec/goqueue/options/consumer"
89
)

encoding.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ type DecoderFn func(ctx context.Context, data []byte) (m interfaces.Message, err
2020
var (
2121
// JSONEncoder is an implementation of the EncoderFn interface
2222
// that encodes a Message into JSON format.
23-
JSONEncoder EncoderFn = func(ctx context.Context, m interfaces.Message) (data []byte, err error) {
23+
JSONEncoder EncoderFn = func(_ context.Context, m interfaces.Message) (data []byte, err error) {
2424
return json.Marshal(m)
2525
}
2626
// JSONDecoder is a DecoderFn implementation that decodes JSON data into a Message.
27-
JSONDecoder DecoderFn = func(ctx context.Context, data []byte) (m interfaces.Message, err error) {
27+
JSONDecoder DecoderFn = func(_ context.Context, data []byte) (m interfaces.Message, err error) {
2828
err = json.Unmarshal(data, &m)
2929
return
3030
}
@@ -73,6 +73,7 @@ var (
7373
DefaultEncoding = JSONEncoding
7474
)
7575

76+
//nolint:gochecknoinits // Required for auto-registration of default JSON encoding
7677
func init() {
7778
AddGoQueueEncoding(JSONEncoding.ContentType, JSONEncoding)
7879
}

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ go 1.23.0
55
require (
66
github.com/google/uuid v1.6.0
77
github.com/rabbitmq/amqp091-go v1.10.0
8-
github.com/sirupsen/logrus v1.9.3
8+
github.com/rs/zerolog v1.34.0
99
github.com/stretchr/testify v1.10.0
1010
go.uber.org/multierr v1.11.0
1111
golang.org/x/sync v0.16.0
1212
)
1313

1414
require (
1515
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/mattn/go-colorable v0.1.13 // indirect
17+
github.com/mattn/go-isatty v0.0.19 // indirect
18+
github.com/pkg/errors v0.9.1 // indirect
1619
github.com/pmezard/go-difflib v1.0.0 // indirect
17-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
20+
golang.org/x/sys v0.12.0 // indirect
1821
gopkg.in/yaml.v3 v3.0.1 // indirect
1922
)

go.sum

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1+
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
45
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
56
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
8+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
9+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
10+
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
11+
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
12+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
13+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
614
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
715
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
816
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
917
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
10-
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
11-
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
12-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
13-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18+
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
19+
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
20+
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
1421
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
1522
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
1623
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@@ -19,10 +26,11 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
1926
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
2027
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
2128
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
22-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
23-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
29+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
31+
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
32+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2433
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2534
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
26-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2735
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2836
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

interfaces/delayfn.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package interfaces
22

3+
// DelayFn is a function type that represents a delay function.
4+
// It takes the current number of retries as input and returns the delay in seconds.
35
type DelayFn func(currenRetries int64) (delay int64)
46

57
var (
@@ -16,8 +18,10 @@ var (
1618
}
1719

1820
// NoDelayFn is a DelayFn implementation that returns 0 delay for retries.
19-
NoDelayFn DelayFn = func(currenRetries int64) (delay int64) {
21+
NoDelayFn DelayFn = func(_ int64) (delay int64) {
2022
return 0
2123
}
24+
// DefaultDelayFn is the default delay function that will be used if no delay function is provided.
25+
// It is set to LinearDelayFn by default.
2226
DefaultDelayFn DelayFn = LinearDelayFn
2327
)

interfaces/inboundmessagehandler.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ type InboundMessageHandlerMiddlewareFunc func(next InboundMessageHandlerFunc) In
1717

1818
type InboundMessage struct {
1919
Message
20-
RetryCount int64 `json:"retryCount"`
21-
Metadata map[string]interface{} `json:"metadata"`
20+
// RetryCount is the number of times the message has been retried.
21+
// This is set by the library to identify the number of times the message has been retried.
22+
RetryCount int64 `json:"retryCount"`
23+
// Metadata is the metadata of the message.
24+
// This is set by the library to identify the metadata of the message.
25+
Metadata map[string]any `json:"metadata"`
2226
// Ack is used for confirming the message. It will drop the message from the queue.
2327
Ack func(ctx context.Context) (err error) `json:"-"`
2428
// Nack is used for rejecting the message. It will requeue the message to be re-delivered again.

0 commit comments

Comments
 (0)