Repository: zeromicro/go-zero
Pull request #3990 (2024-03-09 05:42:29)

chore: fix warnings

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 95.21%. Comparing base [(`2629636`)](https://app.codecov.io/gh/zeromicro/go-zero/commit/2629636f648bd829f5643c63b5359292be565eac?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) to head [(`638ece9`)](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro).
> Report is 20 commits behind head on master.

<details><summary>Additional details and impacted files</summary>



| [Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro) | Coverage Δ | |
|---|---|---|
| [rest/handler/contentsecurityhandler.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-cmVzdC9oYW5kbGVyL2NvbnRlbnRzZWN1cml0eWhhbmRsZXIuZ28=) | `100.00% <100.00%> (ø)` | |
| [rest/httpx/util.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-cmVzdC9odHRweC91dGlsLmdv) | `100.00% <100.00%> (ø)` | |
| [zrpc/internal/rpclogger.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-enJwYy9pbnRlcm5hbC9ycGNsb2dnZXIuZ28=) | `100.00% <100.00%> (ø)` | |
| [zrpc/resolver/internal/resolver.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-enJwYy9yZXNvbHZlci9pbnRlcm5hbC9yZXNvbHZlci5nbw==) | `100.00% <100.00%> (ø)` | |
| [zrpc/resolver/register.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro#diff-enJwYy9yZXNvbHZlci9yZWdpc3Rlci5nbw==) | `100.00% <ø> (ø)` | |

... and [250 files with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3990/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=zeromicro)

</details>

Patch:
diff --git a/internal/mock/depositserver.go b/internal/mock/depositserver.go
index 6f7a6275..d8d6030b 100644
--- a/internal/mock/depositserver.go
+++ b/internal/mock/depositserver.go
@@ -12,7 +12,7 @@ import (
 type DepositServer struct{}
 
 // Deposit handles the deposit requests.
-func (*DepositServer) Deposit(ctx context.Context, req *DepositRequest) (*DepositResponse, error) {
+func (*DepositServer) Deposit(_ context.Context, req *DepositRequest) (*DepositResponse, error) {
 	if req.GetAmount() < 0 {
 		return nil, status.Errorf(codes.InvalidArgument, "cannot deposit %v", req.GetAmount())
 	}
diff --git a/rest/handler/contentsecurityhandler.go b/rest/handler/contentsecurityhandler.go
index a5b9c182..bd095fe9 100644
--- a/rest/handler/contentsecurityhandler.go
+++ b/rest/handler/contentsecurityhandler.go
@@ -60,7 +60,8 @@ func executeCallbacks(w http.ResponseWriter, r *http.Request, next http.Handler,
 	}
 }
 
-func handleVerificationFailure(w http.ResponseWriter, r *http.Request, next http.Handler, strict bool, code int) {
+func handleVerificationFailure(w http.ResponseWriter, r *http.Request, next http.Handler,
+	strict bool, _ int) {
 	if strict {
 		w.WriteHeader(http.StatusForbidden)
 	} else {
diff --git a/rest/httpx/util.go b/rest/httpx/util.go
index 23419614..9623761a 100644
--- a/rest/httpx/util.go
+++ b/rest/httpx/util.go
@@ -1,6 +1,9 @@
 package httpx
 
-import "net/http"
+import (
+	"errors"
+	"net/http"
+)
 
 const xForwardedFor = "X-Forwarded-For"
 
@@ -11,7 +14,7 @@ func GetFormValues(r *http.Request) (map[string]any, error) {
 	}
 
 	if err := r.ParseMultipartForm(maxMemory); err != nil {
-		if err != http.ErrNotMultipart {
+		if !errors.Is(err, http.ErrNotMultipart) {
 			return nil, err
 		}
 	}
diff --git a/zrpc/internal/rpclogger.go b/zrpc/internal/rpclogger.go
index d20887a2..e871bb58 100644
--- a/zrpc/internal/rpclogger.go
+++ b/zrpc/internal/rpclogger.go
@@ -46,17 +46,17 @@ func (l *Logger) Fatalln(args ...any) {
 }
 
 // Info ignores the grpc info logs.
-func (l *Logger) Info(args ...any) {
+func (l *Logger) Info(_ ...any) {
 	// ignore builtin grpc info
 }
 
 // Infoln ignores the grpc info logs.
-func (l *Logger) Infoln(args ...any) {
+func (l *Logger) Infoln(_ ...any) {
 	// ignore builtin grpc info
 }
 
 // Infof ignores the grpc info logs.
-func (l *Logger) Infof(format string, args ...any) {
+func (l *Logger) Infof(_ string, _ ...any) {
 	// ignore builtin grpc info
 }
 
@@ -66,16 +66,16 @@ func (l *Logger) V(v int) bool {
 }
 
 // Warning ignores the grpc warning logs.
-func (l *Logger) Warning(args ...any) {
+func (l *Logger) Warning(_ ...any) {
 	// ignore builtin grpc warning
 }
 
 // Warningf ignores the grpc warning logs.
-func (l *Logger) Warningf(format string, args ...any) {
+func (l *Logger) Warningf(_ string, _ ...any) {
 	// ignore builtin grpc warning
 }
 
 // Warningln ignores the grpc warning logs.
-func (l *Logger) Warningln(args ...any) {
+func (l *Logger) Warningln(_ ...any) {
 	// ignore builtin grpc warning
 }
diff --git a/zrpc/resolver/internal/resolver.go b/zrpc/resolver/internal/resolver.go
index 37362a07..2d64ccc8 100644
--- a/zrpc/resolver/internal/resolver.go
+++ b/zrpc/resolver/internal/resolver.go
@@ -46,5 +46,5 @@ type nopResolver struct {
 func (r *nopResolver) Close() {
 }
 
-func (r *nopResolver) ResolveNow(options resolver.ResolveNowOptions) {
+func (r *nopResolver) ResolveNow(_ resolver.ResolveNowOptions) {
 }
diff --git a/zrpc/resolver/register.go b/zrpc/resolver/register.go
index 43a1ffd2..cc1d04e6 100644
--- a/zrpc/resolver/register.go
+++ b/zrpc/resolver/register.go
@@ -1,8 +1,6 @@
 package resolver
 
-import (
-	"github.com/zeromicro/go-zero/zrpc/resolver/internal"
-)
+import "github.com/zeromicro/go-zero/zrpc/resolver/internal"
 
 // Register registers schemes defined zrpc.
 // Keep it in a separated package to let third party register manually.


Test patch:
diff --git a/rest/engine_test.go b/rest/engine_test.go
index fe5358f1..4f86d217 100644
--- a/rest/engine_test.go
+++ b/rest/engine_test.go
@@ -435,7 +435,7 @@ type mockedRouter struct {
 func (m mockedRouter) ServeHTTP(_ http.ResponseWriter, _ *http.Request) {
 }
 
-func (m mockedRouter) Handle(_, _ string, handler http.Handler) error {
+func (m mockedRouter) Handle(_, _ string, _ http.Handler) error {
 	return errors.New("foo")
 }
 
diff --git a/rest/handler/contentsecurityhandler_test.go b/rest/handler/contentsecurityhandler_test.go
index dfbcc9db..6da9820c 100644
--- a/rest/handler/contentsecurityhandler_test.go
+++ b/rest/handler/contentsecurityhandler_test.go
@@ -327,7 +327,7 @@ func buildRequest(rs requestSettings) (*http.Request, error) {
 			query,
 			bodySign,
 		}, "\n")
-		rs.signature = codec.HmacBase64([]byte(key), contentOfSign)
+		rs.signature = codec.HmacBase64(key, contentOfSign)
 	}
 
 	var mode string
diff --git a/rest/handler/cryptionhandler_test.go b/rest/handler/cryptionhandler_test.go
index b76384d6..f993cac5 100644
--- a/rest/handler/cryptionhandler_test.go
+++ b/rest/handler/cryptionhandler_test.go
@@ -224,7 +224,7 @@ func (m flushableResponseWriter) Write(p []byte) (int, error) {
 	return m.writer.Write(p)
 }
 
-func (m flushableResponseWriter) WriteHeader(statusCode int) {
+func (m flushableResponseWriter) WriteHeader(_ int) {
 	panic("implement me")
 }
 
@@ -240,6 +240,6 @@ func (t *halfWriter) Write(p []byte) (n int, err error) {
 type badWriter struct {
 }
 
-func (b *badWriter) Write(p []byte) (n int, err error) {
+func (b *badWriter) Write(_ []byte) (n int, err error) {
 	return 0, io.ErrClosedPipe
 }
diff --git a/rest/handler/loghandler_test.go b/rest/handler/loghandler_test.go
index c5763379..b6f81e1d 100644
--- a/rest/handler/loghandler_test.go
+++ b/rest/handler/loghandler_test.go
@@ -164,7 +164,7 @@ type mockedReadCloser struct {
 	errMsg string
 }
 
-func (m mockedReadCloser) Read(p []byte) (n int, err error) {
+func (m mockedReadCloser) Read(_ []byte) (n int, err error) {
 	return 0, errors.New(m.errMsg)
 }
 
diff --git a/rest/httpc/responses_test.go b/rest/httpc/responses_test.go
index 31369ee1..c6c7dd3e 100644
--- a/rest/httpc/responses_test.go
+++ b/rest/httpc/responses_test.go
@@ -175,6 +175,6 @@ func (m mockedReader) Close() error {
 	return nil
 }
 
-func (m mockedReader) Read(p []byte) (n int, err error) {
+func (m mockedReader) Read(_ []byte) (n int, err error) {
 	return 0, errors.New("dummy")
 }
diff --git a/zrpc/internal/balancer/p2c/p2c_test.go b/zrpc/internal/balancer/p2c/p2c_test.go
index 8d423622..8e1ec4b2 100644
--- a/zrpc/internal/balancer/p2c/p2c_test.go
+++ b/zrpc/internal/balancer/p2c/p2c_test.go
@@ -142,7 +142,7 @@ func (m mockClientConn) GetOrBuildProducer(builder balancer.ProducerBuilder) (
 	return builder.Build(m)
 }
 
-func (m mockClientConn) UpdateAddresses(addresses []resolver.Address) {
+func (m mockClientConn) UpdateAddresses(_ []resolver.Address) {
 }
 
 func (m mockClientConn) Connect() {
diff --git a/zrpc/internal/clientinterceptors/tracinginterceptor_test.go b/zrpc/internal/clientinterceptors/tracinginterceptor_test.go
index 91952ef4..3c25d50c 100644
--- a/zrpc/internal/clientinterceptors/tracinginterceptor_test.go
+++ b/zrpc/internal/clientinterceptors/tracinginterceptor_test.go
@@ -420,10 +420,10 @@ func (m *mockedClientStream) Context() context.Context {
 	return context.Background()
 }
 
-func (m *mockedClientStream) SendMsg(v any) error {
+func (m *mockedClientStream) SendMsg(_ any) error {
 	return m.err
 }
 
-func (m *mockedClientStream) RecvMsg(v any) error {
+func (m *mockedClientStream) RecvMsg(_ any) error {
 	return m.err
 }
diff --git a/zrpc/internal/serverinterceptors/authinterceptor_test.go b/zrpc/internal/serverinterceptors/authinterceptor_test.go
index 12d83a09..3b09b7cb 100644
--- a/zrpc/internal/serverinterceptors/authinterceptor_test.go
+++ b/zrpc/internal/serverinterceptors/authinterceptor_test.go
@@ -169,25 +169,25 @@ type mockedStream struct {
 	ctx context.Context
 }
 
-func (m mockedStream) SetHeader(md metadata.MD) error {
+func (m mockedStream) SetHeader(_ metadata.MD) error {
 	return nil
 }
 
-func (m mockedStream) SendHeader(md metadata.MD) error {
+func (m mockedStream) SendHeader(_ metadata.MD) error {
 	return nil
 }
 
-func (m mockedStream) SetTrailer(md metadata.MD) {
+func (m mockedStream) SetTrailer(_ metadata.MD) {
 }
 
 func (m mockedStream) Context() context.Context {
 	return m.ctx
 }
 
-func (m mockedStream) SendMsg(v any) error {
+func (m mockedStream) SendMsg(_ any) error {
 	return nil
 }
 
-func (m mockedStream) RecvMsg(v any) error {
+func (m mockedStream) RecvMsg(_ any) error {
 	return nil
 }
diff --git a/zrpc/internal/serverinterceptors/tracinginterceptor_test.go b/zrpc/internal/serverinterceptors/tracinginterceptor_test.go
index 9fb85a9b..2b3fee86 100644
--- a/zrpc/internal/serverinterceptors/tracinginterceptor_test.go
+++ b/zrpc/internal/serverinterceptors/tracinginterceptor_test.go
@@ -309,15 +309,15 @@ type mockedServerStream struct {
 	err error
 }
 
-func (m *mockedServerStream) SetHeader(md metadata.MD) error {
+func (m *mockedServerStream) SetHeader(_ metadata.MD) error {
 	panic("implement me")
 }
 
-func (m *mockedServerStream) SendHeader(md metadata.MD) error {
+func (m *mockedServerStream) SendHeader(_ metadata.MD) error {
 	panic("implement me")
 }
 
-func (m *mockedServerStream) SetTrailer(md metadata.MD) {
+func (m *mockedServerStream) SetTrailer(_ metadata.MD) {
 	panic("implement me")
 }
 
@@ -329,10 +329,10 @@ func (m *mockedServerStream) Context() context.Context {
 	return m.ctx
 }
 
-func (m *mockedServerStream) SendMsg(v any) error {
+func (m *mockedServerStream) SendMsg(_ any) error {
 	return m.err
 }
 
-func (m *mockedServerStream) RecvMsg(v any) error {
+func (m *mockedServerStream) RecvMsg(_ any) error {
 	return m.err
 }
diff --git a/zrpc/resolver/internal/resolver_test.go b/zrpc/resolver/internal/resolver_test.go
index 62c82387..7dd10ee7 100644
--- a/zrpc/resolver/internal/resolver_test.go
+++ b/zrpc/resolver/internal/resolver_test.go
@@ -28,15 +28,15 @@ func (m *mockedClientConn) UpdateState(state resolver.State) error {
 	return m.err
 }
 
-func (m *mockedClientConn) ReportError(err error) {
+func (m *mockedClientConn) ReportError(_ error) {
 }
 
-func (m *mockedClientConn) NewAddress(addresses []resolver.Address) {
+func (m *mockedClientConn) NewAddress(_ []resolver.Address) {
 }
 
-func (m *mockedClientConn) NewServiceConfig(serviceConfig string) {
+func (m *mockedClientConn) NewServiceConfig(_ string) {
 }
 
-func (m *mockedClientConn) ParseServiceConfig(serviceConfigJSON string) *serviceconfig.ParseResult {
+func (m *mockedClientConn) ParseServiceConfig(_ string) *serviceconfig.ParseResult {
 	return nil
 }