diff --git a/.golangci.yml b/.golangci.yml index 79e1197..4ef0441 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-05-27T14:20:35Z by kres b5844f8. +# Generated on 2024-10-10T19:23:45Z by kres 34e72ac. # options for analysis running run: @@ -13,8 +13,8 @@ run: # output configuration options output: formats: - - format: colored-line-number - path: stdout + - format: colored-line-number + path: stdout print-issued-lines: true print-linter-name: true uniq-by-line: true @@ -94,13 +94,15 @@ linters-settings: cyclop: # the maximal code complexity to report max-complexity: 20 - # depguard: - # rules: - # Main: - # list-mode: lax - # deny: - # - pkg: github.com/OpenPeeDeeP/depguard - # desc: this is just an example + depguard: + rules: + prevent_unmaintained_packages: + list-mode: lax # allow unless explicitly denied + files: + - $all + deny: + - pkg: io/ioutil + desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil" linters: enable-all: true @@ -126,18 +128,13 @@ linters: - tagalign - tagliatelle - thelper - - typecheck - varnamelen - wrapcheck - - depguard # an Allow and/or Deny package list must be configured - testifylint # complains about our assert recorder and has a number of false positives for assert.Greater(t, thing, 1) - protogetter # complains about us using Value field on typed spec, instead of GetValue which has a different signature - perfsprint # complains about us using fmt.Sprintf in non-performance critical code, updating just kres took too long - # abandoned linters for which golangci shows the warning that the repo is archived by the owner - - execinquery - # disabled as it seems to be broken - goes into imported libraries and reports issues there - - musttag - goimports # same as gci + - musttag # seems to be broken - goes into imported libraries and reports issues there issues: exclude: [ ] diff --git a/Dockerfile b/Dockerfile index 71db035..46389c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,18 @@ -# syntax = docker/dockerfile-upstream:1.7.1-labs +# syntax = docker/dockerfile-upstream:1.10.0-labs # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-05-27T14:20:35Z by kres b5844f8. +# Generated on 2024-10-10T19:23:45Z by kres 34e72ac. ARG TOOLCHAIN # runs markdownlint -FROM docker.io/node:22.2.0-alpine3.19 AS lint-markdown +FROM docker.io/oven/bun:1.1.29-alpine AS lint-markdown WORKDIR /src -RUN npm i -g markdownlint-cli@0.40.0 -RUN npm i sentences-per-line@0.2.1 +RUN bun i markdownlint-cli@0.41.0 sentences-per-line@0.2.1 COPY .markdownlint.json . COPY ./README.md ./README.md -RUN markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js . +RUN bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js . # collects proto specs FROM scratch AS proto-specs @@ -25,14 +24,17 @@ RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev # build tools FROM --platform=${BUILDPLATFORM} toolchain AS tools -ENV GO111MODULE on +ENV GO111MODULE=on ARG CGO_ENABLED -ENV CGO_ENABLED ${CGO_ENABLED} +ENV CGO_ENABLED=${CGO_ENABLED} ARG GOTOOLCHAIN -ENV GOTOOLCHAIN ${GOTOOLCHAIN} +ENV GOTOOLCHAIN=${GOTOOLCHAIN} ARG GOEXPERIMENT -ENV GOEXPERIMENT ${GOEXPERIMENT} -ENV GOPATH /go +ENV GOEXPERIMENT=${GOEXPERIMENT} +ENV GOPATH=/go +ARG GOIMPORTS_VERSION +RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install golang.org/x/tools/cmd/goimports@v${GOIMPORTS_VERSION} +RUN mv /go/bin/goimports /bin ARG PROTOBUF_GO_VERSION RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install google.golang.org/protobuf/cmd/protoc-gen-go@v${PROTOBUF_GO_VERSION} RUN mv /go/bin/protoc-gen-go /bin @@ -42,9 +44,6 @@ RUN mv /go/bin/protoc-gen-go-grpc /bin ARG GRPC_GATEWAY_VERSION RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} RUN mv /go/bin/protoc-gen-grpc-gateway /bin -ARG GOIMPORTS_VERSION -RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install golang.org/x/tools/cmd/goimports@v${GOIMPORTS_VERSION} -RUN mv /go/bin/goimports /bin ARG DEEPCOPY_VERSION RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \ && mv /go/bin/deep-copy /bin/deep-copy @@ -85,7 +84,7 @@ RUN FILES="$(gofumpt -l .)" && test -z "${FILES}" || (echo -e "Source code is no FROM base AS lint-golangci-lint WORKDIR /src COPY .golangci.yml . -ENV GOGC 50 +ENV GOGC=50 RUN golangci-lint config verify --config .golangci.yml RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/root/.cache/golangci-lint --mount=type=cache,target=/go/pkg golangci-lint run --config .golangci.yml diff --git a/Makefile b/Makefile index ad5a1de..3b29c06 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-05-27T14:20:53Z by kres b5844f8. +# Generated on 2024-10-10T19:23:45Z by kres 34e72ac. # common variables @@ -17,15 +17,15 @@ WITH_RACE ?= false REGISTRY ?= ghcr.io USERNAME ?= siderolabs REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) -PROTOBUF_GO_VERSION ?= 1.34.1 -GRPC_GO_VERSION ?= 1.3.0 -GRPC_GATEWAY_VERSION ?= 2.20.0 +PROTOBUF_GO_VERSION ?= 1.34.2 +GRPC_GO_VERSION ?= 1.5.1 +GRPC_GATEWAY_VERSION ?= 2.22.0 VTPROTOBUF_VERSION ?= 0.6.0 -GOIMPORTS_VERSION ?= 0.21.0 +GOIMPORTS_VERSION ?= 0.25.0 DEEPCOPY_VERSION ?= v0.5.6 -GOLANGCILINT_VERSION ?= v1.59.1 -GOFUMPT_VERSION ?= v0.6.0 -GO_VERSION ?= 1.22.3 +GOLANGCILINT_VERSION ?= v1.61.0 +GOFUMPT_VERSION ?= v0.7.0 +GO_VERSION ?= 1.23.2 GO_BUILDFLAGS ?= GO_LDFLAGS ?= CGO_ENABLED ?= 0 @@ -67,7 +67,7 @@ COMMON_ARGS += --build-arg=DEEPCOPY_VERSION="$(DEEPCOPY_VERSION)" COMMON_ARGS += --build-arg=GOLANGCILINT_VERSION="$(GOLANGCILINT_VERSION)" COMMON_ARGS += --build-arg=GOFUMPT_VERSION="$(GOFUMPT_VERSION)" COMMON_ARGS += --build-arg=TESTPKGS="$(TESTPKGS)" -TOOLCHAIN ?= docker.io/golang:1.22-alpine +TOOLCHAIN ?= docker.io/golang:1.23-alpine # help menu diff --git a/go.mod b/go.mod index 16af387..23b87ca 100644 --- a/go.mod +++ b/go.mod @@ -6,17 +6,17 @@ require ( github.com/golang/protobuf v1.5.4 github.com/hashicorp/go-multierror v1.1.1 github.com/stretchr/testify v1.9.0 - google.golang.org/grpc v1.64.0 - google.golang.org/protobuf v1.34.1 + google.golang.org/grpc v1.67.1 + google.golang.org/protobuf v1.35.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 2f0a3ca..d98bd7b 100644 --- a/go.sum +++ b/go.sum @@ -4,7 +4,6 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -14,20 +13,20 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e h1:Elxv5MwEkCI9f5SkoL6afed6NTdxaGoAo39eANBwHL8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/hack/release.sh b/hack/release.sh index ef0ba27..53dc147 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -1,8 +1,8 @@ -#!/bin/bash +#!/usr/bin/env bash # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-06-06T17:35:55Z by kres 65530e7. +# Generated on 2024-10-10T19:23:45Z by kres 34e72ac. set -e @@ -44,9 +44,92 @@ function commit { exit 1 fi + if is_on_main_branch; then + update_license_files + fi + git commit -s -m "release($1): prepare release" -m "This is the official $1 release." } +function is_on_main_branch { + main_remotes=("upstream" "origin") + branch_names=("main" "master") + current_branch=$(git rev-parse --abbrev-ref HEAD) + + echo "Check current branch: $current_branch" + + for remote in "${main_remotes[@]}"; do + echo "Fetch remote $remote..." + + if ! git fetch --quiet "$remote" &>/dev/null; then + echo "Failed to fetch $remote, skip..." + + continue + fi + + for branch_name in "${branch_names[@]}"; do + if ! git rev-parse --verify "$branch_name" &>/dev/null; then + echo "Branch $branch_name does not exist, skip..." + + continue + fi + + echo "Branch $remote/$branch_name exists, comparing..." + + merge_base=$(git merge-base "$current_branch" "$remote/$branch_name") + latest_main=$(git rev-parse "$remote/$branch_name") + + if [ "$merge_base" = "$latest_main" ]; then + echo "Current branch is up-to-date with $remote/$branch_name" + + return 0 + else + echo "Current branch is not on $remote/$branch_name" + + return 1 + fi + done + done + + echo "No main or master branch found on any remote" + + return 1 +} + +function update_license_files { + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + parent_dir="$(dirname "$script_dir")" + current_year=$(date +"%Y") + change_date=$(date -v+4y +"%Y-%m-%d" 2>/dev/null || date -d "+4 years" +"%Y-%m-%d" 2>/dev/null || date --date="+4 years" +"%Y-%m-%d") + + # Find LICENSE and .kres.yaml files recursively in the parent directory (project root) + find "$parent_dir" \( -name "LICENSE" -o -name ".kres.yaml" \) -type f | while read -r file; do + temp_file="${file}.tmp" + + if [[ $file == *"LICENSE" ]]; then + if grep -q "^Business Source License" "$file"; then + sed -e "s/The Licensed Work is (c) [0-9]\{4\}/The Licensed Work is (c) $current_year/" \ + -e "s/Change Date: [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/Change Date: $change_date/" \ + "$file" >"$temp_file" + else + continue # Not a Business Source License file + fi + elif [[ $file == *".kres.yaml" ]]; then + sed -E 's/^([[:space:]]*)ChangeDate:.*$/\1ChangeDate: "'"$change_date"'"/' "$file" >"$temp_file" + fi + + # Check if the file has changed + if ! cmp -s "$file" "$temp_file"; then + mv "$temp_file" "$file" + echo "Updated: $file" + git add "$file" + else + echo "No changes: $file" + rm "$temp_file" + fi + done +} + if declare -f "$1" > /dev/null then cmd="$1" @@ -55,7 +138,7 @@ then else cat <%s", c.parentCodec.Name()) } - -// protoCodec is a Codec implementation with protobuf. It is the default rawCodec for gRPC. -type protoCodec struct{} - -func (protoCodec) Marshal(v interface{}) ([]byte, error) { - return proto.Marshal(v.(proto.Message)) //nolint:forcetypeassert -} - -func (protoCodec) Unmarshal(data []byte, v interface{}) error { - return proto.Unmarshal(data, v.(proto.Message)) //nolint:forcetypeassert -} - -func (protoCodec) Name() string { - return "proto" -} diff --git a/proxy/codec_test.go b/proxy/codec_test.go index 3a10e59..0baf686 100644 --- a/proxy/codec_test.go +++ b/proxy/codec_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "google.golang.org/grpc/mem" "github.com/siderolabs/grpc-proxy/proxy" ) @@ -12,14 +13,24 @@ func TestCodec_ReadYourWrites(t *testing.T) { framePtr := proxy.NewFrame(nil) data := []byte{0xDE, 0xAD, 0xBE, 0xEF} codec := proxy.Codec() - require.NoError(t, codec.Unmarshal(data, framePtr), "unmarshalling must go ok") + + buffer := mem.Copy(data, mem.DefaultBufferPool()) + defer buffer.Free() + + require.NoError(t, codec.Unmarshal(mem.BufferSlice{buffer}, framePtr), "unmarshalling must go ok") out, err := codec.Marshal(framePtr) require.NoError(t, err, "no marshal error") - require.Equal(t, data, out, "output and data must be the same") + require.Equal(t, data, out.Materialize(), "output and data must be the same") + + out.Free() + buffer.Free() + buffer = mem.Copy([]byte{0x55}, mem.DefaultBufferPool()) // reuse - require.NoError(t, codec.Unmarshal([]byte{0x55}, framePtr), "unmarshalling must go ok") + require.NoError(t, codec.Unmarshal(mem.BufferSlice{buffer}, framePtr), "unmarshalling must go ok") out, err = codec.Marshal(framePtr) require.NoError(t, err, "no marshal error") - require.Equal(t, []byte{0x55}, out, "output and data must be the same") + require.Equal(t, []byte{0x55}, out.Materialize(), "output and data must be the same") + + out.Free() } diff --git a/proxy/examples_test.go b/proxy/examples_test.go index 5522646..f49ecc6 100644 --- a/proxy/examples_test.go +++ b/proxy/examples_test.go @@ -22,7 +22,7 @@ var director proxy.StreamDirector // ExampleRegisterService is a simple example of registering a service with the proxy. func ExampleRegisterService() { // A gRPC server with the proxying codec enabled. - server := grpc.NewServer(grpc.ForceServerCodec(proxy.Codec())) + server := grpc.NewServer(grpc.ForceServerCodecV2(proxy.Codec())) // Register a TestService with 4 of its methods explicitly. proxy.RegisterService(server, director, @@ -37,7 +37,7 @@ func ExampleRegisterService() { // ExampleTransparentHandler is an example of redirecting all requests to the proxy. func ExampleTransparentHandler() { grpc.NewServer( - grpc.ForceServerCodec(proxy.Codec()), + grpc.ForceServerCodecV2(proxy.Codec()), grpc.UnknownServiceHandler(proxy.TransparentHandler(director)), ) @@ -50,7 +50,7 @@ func ExampleStreamDirector() { simpleBackendGen := func(hostname string) (proxy.Backend, error) { conn, err := grpc.NewClient( hostname, - grpc.WithDefaultCallOptions(grpc.ForceCodec(proxy.Codec())), + grpc.WithDefaultCallOptions(grpc.ForceCodecV2(proxy.Codec())), grpc.WithTransportCredentials(insecure.NewCredentials()), ) if err != nil { diff --git a/proxy/handler.go b/proxy/handler.go index 1605be0..e915978 100644 --- a/proxy/handler.go +++ b/proxy/handler.go @@ -63,7 +63,7 @@ func (s *handler) handler(_ any, serverStream grpc.ServerStream) error { // We require that the backend's returned context inherits from the serverStream.Context(). var outgoingCtx context.Context - outgoingCtx, backendConnections[i].backendConn, backendConnections[i].connError = backends[i].GetConnection(clientCtx, fullMethodName) //nolint:fatcontext + outgoingCtx, backendConnections[i].backendConn, backendConnections[i].connError = backends[i].GetConnection(clientCtx, fullMethodName) if backendConnections[i].connError != nil { continue diff --git a/proxy/handler_one2many.go b/proxy/handler_one2many.go index 8b1fe49..6a197dc 100644 --- a/proxy/handler_one2many.go +++ b/proxy/handler_one2many.go @@ -109,7 +109,7 @@ func (s *handler) forwardClientsToServerMultiUnary(sources []backendConnection, payloadCh := make(chan []byte, len(sources)) errCh := make(chan error, len(sources)) - for i := range len(sources) { + for i := range sources { go func(src *backendConnection) { errCh <- func() error { if src.connError != nil { diff --git a/proxy/handler_one2many_test.go b/proxy/handler_one2many_test.go index fdf4c97..39cafb7 100644 --- a/proxy/handler_one2many_test.go +++ b/proxy/handler_one2many_test.go @@ -562,7 +562,7 @@ func (s *ProxyOne2ManySuite) SetupSuite() { conn, err = grpc.NewClient( s.serverListeners[i].Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithDefaultCallOptions(grpc.ForceCodec(proxy.Codec())), + grpc.WithDefaultCallOptions(grpc.ForceCodecV2(proxy.Codec())), ) require.NoError(s.T(), err) @@ -621,7 +621,7 @@ func (s *ProxyOne2ManySuite) SetupSuite() { } s.proxy = grpc.NewServer( - grpc.ForceServerCodec(proxy.Codec()), + grpc.ForceServerCodecV2(proxy.Codec()), grpc.UnknownServiceHandler(proxy.TransparentHandler(director)), ) // Ping handler is handled as an explicit registration and not as a TransparentHandler. diff --git a/proxy/handler_one2one_test.go b/proxy/handler_one2one_test.go index 2f5d959..28cd215 100644 --- a/proxy/handler_one2one_test.go +++ b/proxy/handler_one2one_test.go @@ -229,7 +229,7 @@ func (s *ProxyOne2OneSuite) SetupSuite() { s.serverClientConn, err = grpc.NewClient( s.serverListener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithDefaultCallOptions(grpc.ForceCodec(proxy.Codec())), + grpc.WithDefaultCallOptions(grpc.ForceCodecV2(proxy.Codec())), ) require.NoError(s.T(), err, "must not error on deferred client Dial") @@ -255,7 +255,7 @@ func (s *ProxyOne2OneSuite) SetupSuite() { } s.proxy = grpc.NewServer( - grpc.ForceServerCodec(proxy.Codec()), + grpc.ForceServerCodecV2(proxy.Codec()), grpc.UnknownServiceHandler(proxy.TransparentHandler(director)), ) diff --git a/proxy/proxy.go b/proxy/proxy.go index 9c11389..1484797 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -75,7 +75,7 @@ func RegisterService(server grpc.ServiceRegistrar, director StreamDirector, serv fakeDesc := &grpc.ServiceDesc{ ServiceName: serviceName, - HandlerType: (*interface{})(nil), + HandlerType: (*any)(nil), } for _, m := range streamer.options.methodNames { diff --git a/proxy/serverstream.go b/proxy/serverstream.go index fc7da70..bbfd277 100644 --- a/proxy/serverstream.go +++ b/proxy/serverstream.go @@ -77,7 +77,7 @@ func (wrapper *ServerStreamWrapper) SetTrailer(md metadata.MD) { // It is safe to have a goroutine calling SendMsg and another goroutine // calling RecvMsg on the same stream at the same time, but it is not safe // to call SendMsg on the same stream in different goroutines. -func (wrapper *ServerStreamWrapper) SendMsg(m interface{}) error { +func (wrapper *ServerStreamWrapper) SendMsg(m any) error { wrapper.sendMu.Lock() defer wrapper.sendMu.Unlock()