From 459d3025c5fcc64a973a0c750155d76f99bc8ee9 Mon Sep 17 00:00:00 2001 From: mongobaba <66656234+mongobaba@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:49:16 +0800 Subject: [PATCH] optimize: change err == xx to errors.Is(err, xx) (#3991) --- 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 afa81652..9f20498f 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 18612b7b..5f09f94a 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 758bc2f6..65761a10 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 e69640a3..40284617 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 006c4691..4a7e211e 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)