From e9e55125a9083219bf7f0a36069ff2f155fea46c Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 9 Mar 2024 13:48:11 +0800 Subject: [PATCH] chore: fix warnings (#3990) --- internal/mock/depositserver.go | 2 +- rest/engine_test.go | 2 +- rest/handler/contentsecurityhandler.go | 3 ++- rest/handler/contentsecurityhandler_test.go | 2 +- rest/handler/cryptionhandler_test.go | 4 ++-- rest/handler/loghandler_test.go | 2 +- rest/httpc/responses_test.go | 2 +- rest/httpx/util.go | 7 +++++-- zrpc/internal/balancer/p2c/p2c_test.go | 2 +- .../clientinterceptors/tracinginterceptor_test.go | 4 ++-- zrpc/internal/rpclogger.go | 12 ++++++------ .../serverinterceptors/authinterceptor_test.go | 10 +++++----- .../serverinterceptors/tracinginterceptor_test.go | 10 +++++----- zrpc/resolver/internal/resolver.go | 2 +- zrpc/resolver/internal/resolver_test.go | 8 ++++---- zrpc/resolver/register.go | 4 +--- 16 files changed, 39 insertions(+), 37 deletions(-) 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/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.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/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/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/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/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/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.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/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 } 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.