Skip to content

Commit 38d15df

Browse files
authored
Merge pull request #20 from zerodha/refactor-config
Add a few refactors
2 parents 511e9f3 + d5d7940 commit 38d15df

File tree

8 files changed

+241
-216
lines changed

8 files changed

+241
-216
lines changed

.goreleaser.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ before:
44

55
builds:
66
- env:
7-
- CGO_ENABLED=1
7+
- CGO_ENABLED=0
88
binary: kaf-relay
99
goos:
1010
- linux
1111
goarch:
1212
- amd64
13+
ldflags:
14+
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" -X "main.versionString={{ .Tag }}"
1315

1416
archives:
1517
- format: tar.gz
1618
files:
1719
- config.toml.sample
1820
- README.md
19-
- LICENSE
21+
- LICENSE

Makefile

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# Git version for injecting into Go bins.
2-
LAST_COMMIT := $(shell git rev-parse --short HEAD)
3-
LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT})
4-
VERSION := $(shell git describe --tags)
5-
BUILDSTR := ${VERSION} (Commit: ${LAST_COMMIT_DATE} (${LAST_COMMIT}), Build: $(shell date +"%Y-%m-%d% %H:%M:%S %z"))
1+
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
2+
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"")
63

7-
BIN := kaf-relay.bin
8-
DIST := dist
4+
# Try to get the semver from 1) git 2) the VERSION file 3) fallback.
5+
VERSION := $(or $(LISTMONK_VERSION),$(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP 'tag: \Kv\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?' VERSION),"v0.0.0")
6+
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
97

10-
.PHONY: dist
11-
dist:
12-
mkdir -p ${DIST}
13-
CGO_ENABLED=1 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"
14-
cp ${BIN} ${DIST}
8+
BIN := kaf-relay
9+
10+
.PHONY: build
11+
build: $(BIN)
12+
13+
$(BIN):
14+
CGO_ENABLED=0 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"
1515

1616
.PHONY: clean
1717
clean:
18-
rm -rf ${DIST}
18+
rm -rf ${BIN}

consumer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type consumer struct {
2525
offsetMgr *offsetManager
2626
nodeTracker *NodeTracker
2727

28-
l *slog.Logger
28+
log *slog.Logger
2929
}
3030

3131
// offsetManager is a holder for the topic offsets.
@@ -74,27 +74,27 @@ func (c *consumer) GetHealthy(ctx context.Context) (int, error) {
7474

7575
// reinit reinitializes the consumer group
7676
func (c *consumer) Connect(ctx context.Context, cfg ConsumerGroupCfg) error {
77-
c.l.Debug("reinitializing consumer group", "broker", cfg.BootstrapBrokers)
77+
c.log.Debug("reinitializing consumer group", "broker", cfg.BootstrapBrokers)
7878

7979
// tcp health check
8080
if ok := healthcheck(ctx, cfg.BootstrapBrokers, c.maxReqTime); !ok {
8181
return ErrorNoHealthy
8282
}
8383

84-
cl, err := initConsumerGroup(ctx, cfg, c.l)
84+
cl, err := initConsumerGroup(ctx, cfg, c.log)
8585
if err != nil {
8686
return err
8787
}
8888

8989
offsets := c.GetOffsets()
9090
if offsets != nil {
91-
err = leaveAndResetOffsets(ctx, cl, cfg, offsets, c.l)
91+
err = leaveAndResetOffsets(ctx, cl, cfg, offsets, c.log)
9292
if err != nil {
93-
c.l.Error("error resetting offsets", "err", err)
93+
c.log.Error("error resetting offsets", "err", err)
9494
return err
9595
}
9696

97-
cl, err = initConsumerGroup(ctx, cfg, c.l)
97+
cl, err = initConsumerGroup(ctx, cfg, c.log)
9898
if err != nil {
9999
return err
100100
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.21
55
require (
66
github.com/knadh/koanf/parsers/toml v0.1.0
77
github.com/knadh/koanf/providers/file v0.1.0
8+
github.com/knadh/koanf/providers/posflag v0.1.0
89
github.com/knadh/koanf/v2 v2.0.1
910
github.com/spf13/pflag v1.0.5
1011
github.com/twmb/franz-go v1.15.4

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ github.com/knadh/koanf/parsers/toml v0.1.0 h1:S2hLqS4TgWZYj4/7mI5m1CQQcWurxUz6OD
1212
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
1313
github.com/knadh/koanf/providers/file v0.1.0 h1:fs6U7nrV58d3CFAFh8VTde8TM262ObYf3ODrc//Lp+c=
1414
github.com/knadh/koanf/providers/file v0.1.0/go.mod h1:rjJ/nHQl64iYCtAW2QQnF0eSmDEX/YZ/eNFj5yR6BvA=
15+
github.com/knadh/koanf/providers/posflag v0.1.0 h1:mKJlLrKPcAP7Ootf4pBZWJ6J+4wHYujwipe7Ie3qW6U=
16+
github.com/knadh/koanf/providers/posflag v0.1.0/go.mod h1:SYg03v/t8ISBNrMBRMlojH8OsKowbkXV7giIbBVgbz0=
1517
github.com/knadh/koanf/v2 v2.0.1 h1:1dYGITt1I23x8cfx8ZnldtezdyaZtfAuRtIFOiRzK7g=
1618
github.com/knadh/koanf/v2 v2.0.1/go.mod h1:ZeiIlIDXTE7w1lMT6UVcNiRAS2/rCeLn/GdLNvY1Dus=
1719
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=

0 commit comments

Comments
 (0)