From 3cb0fbf87795d595389d42dfdf8238b264300c7f Mon Sep 17 00:00:00 2001 From: mongobaba Date: Sat, 9 Mar 2024 19:06:54 +0800 Subject: [PATCH] optimize: change err == xx to errors.Is(err, xx) --- core/iox/textlinescanner.go | 3 ++- core/stores/redis/hook.go | 2 +- tools/goctl/rpc/generator/genpb.go | 3 ++- tools/goctl/util/format/format.go | 2 +- zrpc/internal/clientinterceptors/tracinginterceptor.go | 3 ++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/iox/textlinescanner.go b/core/iox/textlinescanner.go index afa8165273c4..9f20498f1091 100644 --- a/core/iox/textlinescanner.go +++ b/core/iox/textlinescanner.go @@ -2,6 +2,7 @@ package iox import ( "bufio" + "errors" "io" "strings" ) @@ -30,7 +31,7 @@ func (scanner *TextLineScanner) Scan() bool { line, err := scanner.reader.ReadString('\n') scanner.line = strings.TrimRight(line, "\n") - if err == io.EOF { + if errors.Is(err, io.EOF) { scanner.hasNext = false return true } else if err != nil { diff --git a/core/stores/redis/hook.go b/core/stores/redis/hook.go index 18612b7b0452..5f09f94a02e0 100644 --- a/core/stores/redis/hook.go +++ b/core/stores/redis/hook.go @@ -122,7 +122,7 @@ func formatError(err error) string { } switch { - case err == io.EOF: + case errors.Is(err, io.EOF): return "eof" case errors.Is(err, context.DeadlineExceeded): return "context deadline" diff --git a/tools/goctl/rpc/generator/genpb.go b/tools/goctl/rpc/generator/genpb.go index 758bc2f631ff..65761a102906 100644 --- a/tools/goctl/rpc/generator/genpb.go +++ b/tools/goctl/rpc/generator/genpb.go @@ -1,6 +1,7 @@ package generator import ( + "errors" "fmt" "io/fs" "os" @@ -86,7 +87,7 @@ func findPbFile(current string, src string, grpc bool) (string, error) { } return nil }) - if err == os.ErrExist { + if errors.Is(err, os.ErrExist) { return filepath.Dir(filepath.Join(current, ret)), nil } return "", err diff --git a/tools/goctl/util/format/format.go b/tools/goctl/util/format/format.go index e69640a3b2b0..40284617bf0a 100644 --- a/tools/goctl/util/format/format.go +++ b/tools/goctl/util/format/format.go @@ -115,7 +115,7 @@ func split(content string) ([]string, error) { for { r, _, err := reader.ReadRune() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { if buffer.Len() > 0 { list = append(list, buffer.String()) } diff --git a/zrpc/internal/clientinterceptors/tracinginterceptor.go b/zrpc/internal/clientinterceptors/tracinginterceptor.go index 006c4691ab33..4a7e211ec928 100644 --- a/zrpc/internal/clientinterceptors/tracinginterceptor.go +++ b/zrpc/internal/clientinterceptors/tracinginterceptor.go @@ -2,6 +2,7 @@ package clientinterceptors import ( "context" + "errors" "io" ztrace "github.com/zeromicro/go-zero/core/trace" @@ -122,7 +123,7 @@ func (w *clientStream) RecvMsg(m any) error { err := w.ClientStream.RecvMsg(m) if err == nil && !w.desc.ServerStreams { w.sendStreamEvent(receiveEndEvent, nil) - } else if err == io.EOF { + } else if errors.Is(err, io.EOF) { w.sendStreamEvent(receiveEndEvent, nil) } else if err != nil { w.sendStreamEvent(errorEvent, err)