Skip to content

Commit 2b5d9f5

Browse files
authored
chore: qol improvements (#141)
1 parent b5d7a49 commit 2b5d9f5

File tree

14 files changed

+632
-589
lines changed

14 files changed

+632
-589
lines changed

.golangci.yml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
1-
linters-settings:
2-
lll:
3-
line-length: 140
4-
funlen:
5-
lines: 70
6-
1+
version: "2"
72
linters:
8-
disable-all: true
3+
default: none
94
enable:
105
- bodyclose
11-
- errcheck
126
- dupl
7+
- errcheck
138
- exhaustive
149
- funlen
1510
- goconst
1611
- gocritic
1712
- gocyclo
18-
- gosimple
1913
- govet
20-
- gosec
2114
- ineffassign
2215
- lll
2316
- misspell
2417
- nakedret
25-
- gofumpt
18+
- prealloc
2619
- staticcheck
27-
- stylecheck
28-
- typecheck
2920
- unconvert
3021
- unparam
3122
- unused
3223
- whitespace
33-
- prealloc
34-
35-
service:
36-
golangci-lint-version: 1.55.2 # use the fixed version to not introduce new linters unexpectedly
37-
prepare:
38-
- echo "here I can run custom commands, but no preparation needed for this repo"
24+
settings:
25+
funlen:
26+
lines: 70
27+
lll:
28+
line-length: 140
29+
exclusions:
30+
generated: lax
31+
presets:
32+
- comments
33+
- common-false-positives
34+
- legacy
35+
- std-error-handling
36+
paths:
37+
- third_party$
38+
- builtin$
39+
- examples$
40+
formatters:
41+
enable:
42+
- gofumpt
43+
exclusions:
44+
generated: lax
45+
paths:
46+
- third_party$
47+
- builtin$
48+
- examples$

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
default: init
44

55
init:
6-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
7-
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@v0.15.0
6+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.0
7+
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@v0.35.0
88

99
clean:
1010
rm -rf ./build

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ by looking at our [docs](docs/index.md).
1818
+ [Kafka Connector](https://github.com/Trendyol/go-dcp-kafka)
1919
+ [Couchbase Connector](https://github.com/Trendyol/go-dcp-couchbase)
2020
+ [SQL Connector](https://github.com/Trendyol/go-dcp-sql)
21+
+ [MongoDB Connector](https://github.com/Trendyol/go-dcp-mongodb)
2122

2223
### Example
2324

couchbase/lil_membership.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package couchbase
33
import (
44
"context"
55
"errors"
6+
"sort"
7+
"time"
8+
69
"github.com/Trendyol/go-dcp/config"
710
"github.com/Trendyol/go-dcp/helpers"
811
"github.com/Trendyol/go-dcp/logger"
@@ -12,8 +15,6 @@ import (
1215
"github.com/couchbase/gocbcore/v10"
1316
"github.com/couchbase/gocbcore/v10/memd"
1417
"github.com/google/uuid"
15-
"sort"
16-
"time"
1718
)
1819

1920
type lilCbMembership struct {
@@ -28,7 +29,6 @@ type lilCbMembership struct {
2829
lastActiveInstances []Instance
2930
instanceAll []byte
3031
id []byte
31-
clusterJoinTime int64
3232
heartbeatRunning bool
3333
monitorRunning bool
3434
}
@@ -59,9 +59,9 @@ func (h *lilCbMembership) register() {
5959
}
6060

6161
func (h *lilCbMembership) createIndex(ctx context.Context, clusterJoinTime int64) error {
62-
var id = string(h.id)
62+
id := string(h.id)
6363

64-
var instance = Instance{
64+
instance := Instance{
6565
ID: &id,
6666
Type: _type,
6767
HeartbeatTime: clusterJoinTime,
@@ -107,13 +107,16 @@ func (h *lilCbMembership) heartbeat() {
107107
ctx, cancel := context.WithTimeout(context.Background(), h.membershipConfig.Timeout)
108108
defer cancel()
109109

110-
var now = time.Now().UnixNano()
110+
now := time.Now().UnixNano()
111111

112112
payload, _ := sonic.Marshal(now)
113113

114-
var heartbeatPath = append(append(h.id, '.'), []byte(_heartbeatPath)...)
114+
heartbeatPath := append(append(h.id, '.'), []byte(_heartbeatPath)...)
115115

116-
err := CreatePath(ctx, h.client.GetMetaAgent(), h.scopeName, h.collectionName, h.instanceAll, heartbeatPath, payload, memd.SubdocDocFlagMkDoc)
116+
err := CreatePath(
117+
ctx, h.client.GetMetaAgent(),
118+
h.scopeName, h.collectionName, h.instanceAll, heartbeatPath, payload, memd.SubdocDocFlagMkDoc,
119+
)
117120
if err != nil {
118121
logger.Log.Error("error while heartbeat: %v", err)
119122
return

couchbase/observer.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ func (so *observer) needCatchup(seqNo uint64) bool {
102102
}
103103

104104
func (so *observer) waitRollbackMitigation(seqNo uint64) {
105-
for {
106-
if so.checkPersistSeqNo(seqNo) {
107-
break
108-
}
109-
105+
for !so.checkPersistSeqNo(seqNo) {
110106
time.Sleep(so.config.RollbackMitigation.Interval / 5)
111107
}
112108
}

example/go.mod

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,82 @@
11
module example
22

3-
go 1.24
3+
go 1.24.0
44

5-
toolchain go1.24.2
5+
toolchain go1.24.5
66

77
replace github.com/Trendyol/go-dcp => ../.
88

99
require github.com/Trendyol/go-dcp v0.0.0
1010

1111
require (
12-
github.com/andybalholm/brotli v1.1.1 // indirect
13-
github.com/ansrivas/fiberprometheus/v2 v2.7.0 // indirect
12+
github.com/andybalholm/brotli v1.2.0 // indirect
13+
github.com/ansrivas/fiberprometheus/v2 v2.13.0 // indirect
1414
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
1515
github.com/beorn7/perks v1.0.1 // indirect
16-
github.com/bytedance/sonic v1.12.8 // indirect
17-
github.com/bytedance/sonic/loader v0.2.2 // indirect
16+
github.com/bytedance/sonic v1.14.0 // indirect
17+
github.com/bytedance/sonic/loader v0.3.0 // indirect
1818
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1919
github.com/cloudwego/base64x v0.1.5 // indirect
2020
github.com/couchbase/gocbcore/v10 v10.7.1 // indirect
2121
github.com/davecgh/go-spew v1.1.1 // indirect
2222
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
23-
github.com/go-logr/logr v1.4.1 // indirect
24-
github.com/go-openapi/jsonpointer v0.19.6 // indirect
23+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
24+
github.com/go-logr/logr v1.4.3 // indirect
25+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
2526
github.com/go-openapi/jsonreference v0.20.2 // indirect
26-
github.com/go-openapi/swag v0.22.3 // indirect
27-
github.com/gofiber/fiber/v2 v2.52.5 // indirect
27+
github.com/go-openapi/swag v0.23.0 // indirect
28+
github.com/gofiber/fiber/v2 v2.52.9 // indirect
2829
github.com/gogo/protobuf v1.3.2 // indirect
29-
github.com/golang/protobuf v1.5.4 // indirect
3030
github.com/golang/snappy v0.0.4 // indirect
31-
github.com/google/gnostic-models v0.6.8 // indirect
32-
github.com/google/gofuzz v1.2.0 // indirect
31+
github.com/google/gnostic-models v0.6.9 // indirect
32+
github.com/google/go-cmp v0.7.0 // indirect
3333
github.com/google/uuid v1.6.0 // indirect
34-
github.com/gorilla/websocket v1.5.3 // indirect
34+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
3535
github.com/josharian/intern v1.0.0 // indirect
3636
github.com/json-iterator/go v1.1.12 // indirect
37-
github.com/klauspost/compress v1.17.11 // indirect
37+
github.com/klauspost/compress v1.18.0 // indirect
3838
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
3939
github.com/mailru/easyjson v0.7.7 // indirect
4040
github.com/mattn/go-colorable v0.1.13 // indirect
4141
github.com/mattn/go-isatty v0.0.20 // indirect
42-
github.com/mattn/go-runewidth v0.0.15 // indirect
42+
github.com/mattn/go-runewidth v0.0.16 // indirect
4343
github.com/mhmtszr/concurrent-swiss-map v1.0.8 // indirect
4444
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4545
github.com/modern-go/reflect2 v1.0.2 // indirect
4646
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
47-
github.com/prometheus/client_golang v1.20.5 // indirect
47+
github.com/pkg/errors v0.9.1 // indirect
48+
github.com/prometheus/client_golang v1.22.0 // indirect
4849
github.com/prometheus/client_model v0.6.1 // indirect
49-
github.com/prometheus/common v0.58.0 // indirect
50+
github.com/prometheus/common v0.62.0 // indirect
5051
github.com/prometheus/procfs v0.15.1 // indirect
5152
github.com/rivo/uniseg v0.4.7 // indirect
5253
github.com/sirupsen/logrus v1.9.3 // indirect
5354
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
5455
github.com/valyala/bytebufferpool v1.0.0 // indirect
55-
github.com/valyala/fasthttp v1.57.0 // indirect
56-
github.com/valyala/tcplisten v1.0.0 // indirect
56+
github.com/valyala/fasthttp v1.64.0 // indirect
57+
github.com/x448/float16 v0.8.4 // indirect
58+
go.opentelemetry.io/otel v1.37.0 // indirect
59+
go.opentelemetry.io/otel/trace v1.37.0 // indirect
5760
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
58-
golang.org/x/net v0.33.0 // indirect
59-
golang.org/x/oauth2 v0.22.0 // indirect
60-
golang.org/x/sync v0.10.0 // indirect
61-
golang.org/x/sys v0.28.0 // indirect
62-
golang.org/x/term v0.27.0 // indirect
63-
golang.org/x/text v0.21.0 // indirect
64-
golang.org/x/time v0.3.0 // indirect
65-
google.golang.org/protobuf v1.36.4 // indirect
61+
golang.org/x/net v0.42.0 // indirect
62+
golang.org/x/oauth2 v0.27.0 // indirect
63+
golang.org/x/sync v0.16.0 // indirect
64+
golang.org/x/sys v0.34.0 // indirect
65+
golang.org/x/term v0.33.0 // indirect
66+
golang.org/x/text v0.27.0 // indirect
67+
golang.org/x/time v0.9.0 // indirect
68+
google.golang.org/protobuf v1.36.5 // indirect
69+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
6670
gopkg.in/inf.v0 v0.9.1 // indirect
67-
gopkg.in/yaml.v2 v2.4.0 // indirect
6871
gopkg.in/yaml.v3 v3.0.1 // indirect
69-
k8s.io/api v0.29.4 // indirect
70-
k8s.io/apimachinery v0.29.4 // indirect
71-
k8s.io/client-go v0.29.4 // indirect
72-
k8s.io/klog/v2 v2.110.1 // indirect
73-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
74-
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
75-
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
76-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
77-
sigs.k8s.io/yaml v1.3.0 // indirect
72+
k8s.io/api v0.33.3 // indirect
73+
k8s.io/apimachinery v0.33.3 // indirect
74+
k8s.io/client-go v0.33.3 // indirect
75+
k8s.io/klog/v2 v2.130.1 // indirect
76+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
77+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
78+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
79+
sigs.k8s.io/randfill v1.0.0 // indirect
80+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
81+
sigs.k8s.io/yaml v1.4.0 // indirect
7882
)

0 commit comments

Comments
 (0)