mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
optimize: change err == xx to errors.Is(err, xx) (#3991)
This commit is contained in:
parent
e9e55125a9
commit
459d3025c5
@ -2,6 +2,7 @@ package iox
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -30,7 +31,7 @@ func (scanner *TextLineScanner) Scan() bool {
|
|||||||
|
|
||||||
line, err := scanner.reader.ReadString('\n')
|
line, err := scanner.reader.ReadString('\n')
|
||||||
scanner.line = strings.TrimRight(line, "\n")
|
scanner.line = strings.TrimRight(line, "\n")
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
scanner.hasNext = false
|
scanner.hasNext = false
|
||||||
return true
|
return true
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -122,7 +122,7 @@ func formatError(err error) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case err == io.EOF:
|
case errors.Is(err, io.EOF):
|
||||||
return "eof"
|
return "eof"
|
||||||
case errors.Is(err, context.DeadlineExceeded):
|
case errors.Is(err, context.DeadlineExceeded):
|
||||||
return "context deadline"
|
return "context deadline"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
@ -86,7 +87,7 @@ func findPbFile(current string, src string, grpc bool) (string, error) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err == os.ErrExist {
|
if errors.Is(err, os.ErrExist) {
|
||||||
return filepath.Dir(filepath.Join(current, ret)), nil
|
return filepath.Dir(filepath.Join(current, ret)), nil
|
||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -115,7 +115,7 @@ func split(content string) ([]string, error) {
|
|||||||
for {
|
for {
|
||||||
r, _, err := reader.ReadRune()
|
r, _, err := reader.ReadRune()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if errors.Is(err, io.EOF) {
|
||||||
if buffer.Len() > 0 {
|
if buffer.Len() > 0 {
|
||||||
list = append(list, buffer.String())
|
list = append(list, buffer.String())
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package clientinterceptors
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
ztrace "github.com/zeromicro/go-zero/core/trace"
|
ztrace "github.com/zeromicro/go-zero/core/trace"
|
||||||
@ -122,7 +123,7 @@ func (w *clientStream) RecvMsg(m any) error {
|
|||||||
err := w.ClientStream.RecvMsg(m)
|
err := w.ClientStream.RecvMsg(m)
|
||||||
if err == nil && !w.desc.ServerStreams {
|
if err == nil && !w.desc.ServerStreams {
|
||||||
w.sendStreamEvent(receiveEndEvent, nil)
|
w.sendStreamEvent(receiveEndEvent, nil)
|
||||||
} else if err == io.EOF {
|
} else if errors.Is(err, io.EOF) {
|
||||||
w.sendStreamEvent(receiveEndEvent, nil)
|
w.sendStreamEvent(receiveEndEvent, nil)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
w.sendStreamEvent(errorEvent, err)
|
w.sendStreamEvent(errorEvent, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user