Skip to content

Commit 116a3dd

Browse files
authored
Update to buf v2 config and latest golangci-lint (#76)
Update grpchealth-go to use buf v2 config files, golangci-lint v2, and update the Go version in go.mod to 1.23 (reflecting last two releases support).
1 parent 83ff7f6 commit 116a3dd

11 files changed

Lines changed: 77 additions & 65 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
go-version: [1.21.x, 1.22.x, 1.23.x]
18+
go-version: [1.23.x, 1.24.x]
1919
steps:
2020
- name: Checkout Code
2121
uses: actions/checkout@v4
@@ -30,5 +30,5 @@ jobs:
3030
- name: Lint
3131
# Often, lint & gofmt guidelines depend on the Go version. To prevent
3232
# conflicting guidance, run only on the most recent supported version.
33-
if: matrix.go-version == '1.23.x'
33+
if: matrix.go-version == '1.24.x'
3434
run: make checkgenerate && make lint

‎.golangci.yml‎

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,62 @@
1-
linters-settings:
2-
errcheck:
3-
check-type-assertions: true
4-
exhaustruct:
5-
include:
6-
# No zero values for param structs.
7-
- 'connectrpc\.com/grpchealth\..*[pP]arams'
8-
forbidigo:
9-
forbid:
10-
- '^fmt\.Print'
11-
- '^log\.'
12-
- '^print$'
13-
- '^println$'
14-
- '^panic$'
15-
godox:
16-
# TODO, OPT, etc. comments are fine to commit. Use FIXME comments for
17-
# temporary hacks, and use godox to prevent committing them.
18-
keywords: [FIXME]
19-
varnamelen:
20-
ignore-decls:
21-
- T any
22-
- i int
23-
- 't *testing.T'
24-
- tb testing.TB
25-
- wg sync.WaitGroup
1+
version: "2"
262
linters:
27-
enable-all: true
3+
default: all
284
disable:
295
- cyclop # covered by gocyclo
306
- depguard # unnecessary for small libraries
31-
- execinquery # deprecated in golangci 1.58.0
327
- funlen # rely on code review to limit function length
338
- gocognit # dubious "cognitive overhead" quantification
34-
- gofumpt # prefer standard gofmt
35-
- goimports # rely on gci instead
36-
- gomnd # some unnamed constants are okay
379
- inamedparam # convention is not followed
3810
- ireturn # "accept interfaces, return structs" isn't ironclad
3911
- lll # don't want hard limits for line length
4012
- maintidx # covered by gocyclo
13+
- mnd # some unnamed constants are okay
4114
- nlreturn # generous whitespace violates house style
4215
- nonamedreturns # named returns are fine; it's *bare* returns that are bad
43-
- protogetter # too many false positives
4416
- testpackage # internal tests are fine
4517
- wrapcheck # don't _always_ need to wrap errors
4618
- wsl # generous whitespace violates house style
47-
issues:
48-
exclude-dirs-use-default: false
49-
exclude:
50-
# Don't ban use of fmt.Errorf to create new errors, but the remaining
51-
# checks from err113 are useful.
52-
- "do not define dynamic errors.*"
19+
settings:
20+
errcheck:
21+
check-type-assertions: true
22+
exhaustruct:
23+
include:
24+
# No zero values for param structs.
25+
- connectrpc\.com/grpchealth\..*[pP]arams
26+
forbidigo:
27+
forbid:
28+
- pattern: ^fmt\.Print
29+
- pattern: ^log\.
30+
- pattern: ^print$
31+
- pattern: ^println$
32+
- pattern: ^panic$
33+
godox:
34+
# TODO, OPT, etc. comments are fine to commit. Use FIXME comments for
35+
# temporary hacks, and use godox to prevent committing them.
36+
keywords:
37+
- FIXME
38+
varnamelen:
39+
ignore-decls:
40+
- T any
41+
- i int
42+
- t *testing.T
43+
- tb testing.TB
44+
- wg sync.WaitGroup
45+
exclusions:
46+
generated: lax
47+
presets:
48+
- comments
49+
- common-false-positives
50+
- legacy
51+
- std-error-handling
52+
rules:
53+
- linters:
54+
- err113
55+
path: (.+)\.go$
56+
text: do not define dynamic errors.*
57+
formatters:
58+
enable:
59+
- gci
60+
- gofmt
61+
exclusions:
62+
generated: lax

‎Makefile‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ lint: $(BIN)/golangci-lint $(BIN)/buf ## Lint Go and protobuf
3939
test -z "$$($(BIN)/buf format -d . | tee /dev/stderr)"
4040
go vet ./...
4141
golangci-lint run
42+
golangci-lint fmt --diff
4243
buf lint
4344

4445
.PHONY: lintfix
4546
lintfix: $(BIN)/golangci-lint $(BIN)/buf ## Automatically fix some lint errors
4647
golangci-lint run --fix
48+
golangci-lint fmt
4749
buf format -w .
4850

4951
.PHONY: generate
@@ -66,15 +68,15 @@ checkgenerate:
6668

6769
$(BIN)/buf: Makefile
6870
@mkdir -p $(@D)
69-
go install github.com/bufbuild/buf/cmd/buf@v1.29.0
71+
go install github.com/bufbuild/buf/cmd/buf@v1.51.0
7072

7173
$(BIN)/license-header: Makefile
7274
@mkdir -p $(@D)
73-
go install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v1.29.0
75+
go install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v1.51.0
7476

7577
$(BIN)/golangci-lint: Makefile
7678
@mkdir -p $(@D)
77-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.0
79+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2
7880

7981
$(BIN)/protoc-gen-go: Makefile
8082
@mkdir -p $(@D)

‎buf.gen.yaml‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
version: v1
1+
version: v2
22
managed:
33
enabled: true
4-
go_package_prefix:
5-
default: connectrpc.com/grpchealth/internal/gen/go
4+
override:
5+
- file_option: go_package_prefix
6+
value: connectrpc.com/grpchealth/internal/gen/go
67
plugins:
7-
- plugin: go
8+
- local: protoc-gen-go
89
out: internal/gen/go
910
opt: paths=source_relative

‎buf.work.yaml‎

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

‎buf.yaml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: v2
2+
modules:
3+
- path: internal/proto
4+
lint:
5+
use:
6+
- STANDARD
7+
ignore:
8+
- internal/proto/connectext/grpc/health/v1/health.proto
9+
- internal/proto/connectext/grpc/reflection/v1alpha/reflection.proto
10+
- internal/proto/connectext/grpc/status/v1/status.proto
11+
breaking:
12+
use:
13+
- WIRE_JSON

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module connectrpc.com/grpchealth
22

3-
go 1.21
3+
go 1.23
44

55
retract v1.1.1 // module cache poisoned, use v1.1.2
66

‎go.sum‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
connectrpc.com/connect v1.11.0 h1:Av2KQXxSaX4vjqhf5Cl01SX4dqYADQ38eBtr84JSUBk=
22
connectrpc.com/connect v1.11.0/go.mod h1:3AGaO6RRGMx5IKFfqbe3hvK1NqLosFNP2BxDYTPmNPo=
33
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
4+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
45
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
56
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=

‎grpchealth.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func NewHandler(checker Checker, options ...connect.HandlerOption) (string, http
9191
) (*connect.Response[healthv1.HealthCheckResponse], error) {
9292
var checkRequest CheckRequest
9393
if req.Msg != nil {
94-
checkRequest.Service = req.Msg.Service
94+
checkRequest.Service = req.Msg.GetService()
9595
}
9696
checkResponse, err := checker.Check(ctx, &checkRequest)
9797
if err != nil {

‎grpchealth_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func TestHealth(t *testing.T) {
8585
if err != nil {
8686
t.Fatal(err.Error())
8787
}
88-
if Status(res.Msg.Status) != expect {
89-
t.Fatalf("got status %v, expected %v", res.Msg.Status, expect)
88+
if Status(res.Msg.GetStatus()) != expect { //nolint:gosec // Conversion is safe here
89+
t.Fatalf("got status %v, expected %v", res.Msg.GetStatus(), expect)
9090
}
9191
}
9292
assertUnknown := func(

0 commit comments

Comments
 (0)