Skip to content

Commit 728518d

Browse files
authored
Fix lint errors (#100)
* Fix all lint errors * Enable CI lint check * Use 'golanci-lint fmt' and gci to format * Re-run fmt and apply changes
1 parent bcb9ae1 commit 728518d

21 files changed

Lines changed: 97 additions & 58 deletions

.github/workflows/pull-request.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
jobs:
16-
build:
16+
lint:
1717
runs-on: ubuntu-latest
18-
name: sanity checks - pull request
18+
name: lint - pull request
1919
steps:
2020
- name: Checkout
2121
uses: actions/checkout@v4
@@ -33,12 +33,29 @@ jobs:
3333
go-version-file: 'go.mod'
3434
cache: ${{ github.ref == 'refs/heads/main' }} # only update the cache in main.
3535

36+
- name: Run golangci-lint
37+
uses: golangci/golangci-lint-action@v8
38+
with:
39+
version: v2.1
40+
41+
build:
42+
runs-on: ubuntu-latest
43+
name: build and unittest - pull request
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Install go
51+
uses: actions/setup-go@v4
52+
with:
53+
go-version-file: 'go.mod'
54+
cache: ${{ github.ref == 'refs/heads/main' }} # only update the cache in main.
55+
3656
- name: Run go build
3757
run: go build ./...
3858

39-
# - name: Run lint
40-
# run: make lint
41-
4259
- name: Run go unittest
4360
run: make test
4461

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ go.work
2525
go.work.sum
2626

2727
# misc file
28+
!.golangci.yml
2829
/*.yaml
2930
/*.yml
3031
*.pem

.golangci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://golangci-lint.run/usage/configuration/
2+
3+
version: "2"
4+
5+
linters:
6+
default: standard
7+
settings: {}
8+
9+
formatters:
10+
enable:
11+
- gci
12+
settings:
13+
gci:
14+
sections:
15+
- standard
16+
- default
17+
- localmodule
18+
custom-order: true

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ s2s-proxy: $(ALL_SRC)
3030
@printf $(COLOR) "Build s2s-proxy with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)...\n"
3131
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build -o ./bins/s2s-proxy ./cmd/proxy
3232

33-
fmt:
34-
$(GO_TOOL) goimports -local github.com/temporalio/s2s-proxy -w .
35-
3633
update-tools:
37-
$(GO_GET_TOOL) golang.org/x/tools/cmd/goimports@latest
38-
$(GO_GET_TOOL) github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
34+
# When changing the golangci-lint version, update the version in .github/workflows/pull-request.yml
35+
$(GO_GET_TOOL) github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1
3936
go mod tidy --modfile=$(TOOLS_MOD_FILE)
4037

41-
# Lint target
38+
# Refer to .golangci.yml for configuration options
39+
fmt:
40+
$(GO_TOOL) golangci-lint fmt
41+
42+
# Refer to .golangci.yml for configuration options
4243
lint:
4344
@printf $(COLOR) "Running golangci-lint...\n"
4445
$(GO_TOOL) golangci-lint run

client/temporal_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"fmt"
55
"sync"
66

7-
"github.com/temporalio/s2s-proxy/config"
8-
"github.com/temporalio/s2s-proxy/transport"
9-
107
"go.temporal.io/api/workflowservice/v1"
118
"go.temporal.io/server/api/adminservice/v1"
129
"go.temporal.io/server/common/log"
10+
11+
"github.com/temporalio/s2s-proxy/config"
12+
"github.com/temporalio/s2s-proxy/transport"
1313
)
1414

1515
type (

cmd/proxy/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"os/signal"
88
"syscall"
99

10-
"github.com/temporalio/s2s-proxy/client"
11-
"github.com/temporalio/s2s-proxy/config"
12-
"github.com/temporalio/s2s-proxy/proxy"
13-
"github.com/temporalio/s2s-proxy/transport"
14-
1510
"github.com/urfave/cli/v2"
1611
"go.temporal.io/server/common/log"
1712
"go.temporal.io/server/common/log/tag"
1813
"go.uber.org/fx"
14+
15+
"github.com/temporalio/s2s-proxy/client"
16+
"github.com/temporalio/s2s-proxy/config"
17+
"github.com/temporalio/s2s-proxy/proxy"
18+
"github.com/temporalio/s2s-proxy/transport"
1919
)
2020

2121
const (

cmd/tools/genrpcwrappers/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ import (
3939

4040
taskqueuepb "go.temporal.io/api/taskqueue/v1"
4141
"go.temporal.io/api/workflowservice/v1"
42+
"go.temporal.io/server/api/adminservice/v1"
43+
"go.temporal.io/server/api/historyservice/v1"
44+
"go.temporal.io/server/api/matchingservice/v1"
4245
"golang.org/x/text/cases"
4346
"golang.org/x/text/language"
4447
"google.golang.org/protobuf/proto"
4548
"google.golang.org/protobuf/reflect/protoreflect"
4649
"google.golang.org/protobuf/reflect/protoregistry"
47-
48-
"go.temporal.io/server/api/adminservice/v1"
49-
"go.temporal.io/server/api/historyservice/v1"
50-
"go.temporal.io/server/api/matchingservice/v1"
5150
)
5251

5352
type (
@@ -443,13 +442,14 @@ func writeTemplatedMethod(w io.Writer, service service, impl string, m reflect.M
443442
fields["WithLargeTimeout"] = "WithLargeTimeout"
444443
}
445444
if impl == "client" {
446-
if service.name == "history" {
445+
switch service.name {
446+
case "history":
447447
routingOptions := historyRoutingOptions(reqType)
448448
if routingOptions.Custom {
449449
return
450450
}
451451
fields["GetClient"] = makeGetHistoryClient(reqType, routingOptions)
452-
} else if service.name == "matching" {
452+
case "matching":
453453
fields["GetClient"] = makeGetMatchingClient(reqType)
454454
}
455455
}

develop/tools.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ module tools
22

33
go 1.24.4
44

5-
tool (
6-
github.com/golangci/golangci-lint/v2/cmd/golangci-lint
7-
golang.org/x/tools/cmd/goimports
8-
)
5+
tool github.com/golangci/golangci-lint/v2/cmd/golangci-lint
96

107
require (
118
github.com/gogo/status v1.1.1

encryption/tls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func fetchCACert(pathOrUrl string) (caPool *x509.CertPool, err error) {
156156
if err != nil {
157157
return nil, err
158158
}
159-
defer resp.Body.Close()
159+
defer func() { _ = resp.Body.Close() }()
160160
caBytes, err = io.ReadAll(resp.Body)
161161
if err != nil {
162162
return nil, err

interceptor/reflection.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ func visitSearchAttributes(obj any, match stringMatcher) (bool, error) {
130130
case map[string]*common.Payload:
131131
attrs, changed = translateIndexedFields(attrs, match)
132132
if changed {
133-
visit.Assign(vwp, reflect.ValueOf(attrs))
133+
if err := visit.Assign(vwp, reflect.ValueOf(attrs)); err != nil {
134+
return visit.Stop, err
135+
}
134136
}
135137
default:
136138
return visit.Stop, fmt.Errorf("unhandled search attribute type: %T", attrs)

0 commit comments

Comments
 (0)