Skip to content

Commit b06ae94

Browse files
authored
Merge pull request #8 from WJQSERVER-STUDIO/dev
replace to iox
2 parents 1a0ddb9 + 36a23b5 commit b06ae94

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.4
55
require github.com/valyala/bytebufferpool v1.0.0 // indirect
66

77
require (
8-
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6
8+
github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2
99
github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d
1010
golang.org/x/net v0.42.0
1111
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 h1:/50VJYXd6jcu+p5BnEBDyiX0nAyGxas1W3DCnrYMxMY=
2-
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc=
1+
github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2 h1:AiIHXP21LpK7pFfqUlUstgQEWzjbekZgxOuvVwiMfyM=
2+
github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2/go.mod h1:mCLqYU32bTmEE6dpj37MKKiZgz70Jh/xyK9vVbq6pok=
33
github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d h1:+d6m5Bjvv0/RJct1VcOw2P5bvBOGjENmxORJYnSYDow=
44
github.com/go-json-experiment/json v0.0.0-20250714165856-be8212f5270d/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
55
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=

httpc.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/go-json-experiment/json"
2222
"golang.org/x/net/proxy"
2323

24-
"github.com/WJQSERVER-STUDIO/go-utils/copyb"
24+
"github.com/WJQSERVER-STUDIO/go-utils/iox"
2525
)
2626

2727
// 错误定义
@@ -795,7 +795,7 @@ func (c *Client) retryRoundTripper(next http.RoundTripper) http.RoundTripper {
795795

796796
// 在重试前,确保关闭当前失败的响应体以复用连接
797797
if resp != nil && resp.Body != nil {
798-
copyb.Copy(io.Discard, resp.Body)
798+
iox.Copy(io.Discard, resp.Body)
799799
resp.Body.Close()
800800
}
801801

@@ -1092,9 +1092,9 @@ func (c *Client) decodeTextResponse(resp *http.Response) (string, error) {
10921092
return "", c.errorResponse(resp)
10931093
}
10941094

1095-
bodyBytes, err := copyb.ReadAll(resp.Body)
1095+
bodyBytes, err := iox.ReadAll(resp.Body)
10961096
if err != nil {
1097-
return "", fmt.Errorf("%w: %v", ErrDecodeResponse, err)
1097+
return "", fmt.Errorf("%w: %s", err, ErrDecodeResponse)
10981098
}
10991099
return string(bodyBytes), nil
11001100
}
@@ -1103,9 +1103,9 @@ func (c *Client) decodeBytesResponse(resp *http.Response) ([]byte, error) {
11031103
if resp.StatusCode >= 400 {
11041104
return nil, c.errorResponse(resp)
11051105
}
1106-
bodyBytes, err := copyb.ReadAll(resp.Body)
1106+
bodyBytes, err := iox.ReadAll(resp.Body)
11071107
if err != nil {
1108-
return nil, fmt.Errorf("%w: %v", ErrDecodeResponse, err)
1108+
return nil, fmt.Errorf("%w: %s", err, ErrDecodeResponse)
11091109
}
11101110
return bodyBytes, nil
11111111
}
@@ -1146,14 +1146,14 @@ func (c *Client) errorResponse(resp *http.Response) error {
11461146

11471147
limitedReader := io.LimitReader(resp.Body, maxErrorBodyRead)
11481148
readErr := func() error { // 使用匿名函数捕获读取错误
1149-
_, err := copyb.Copy(buf, limitedReader)
1149+
_, err := iox.Copy(buf, limitedReader)
11501150
return err
11511151
}() // 立即执行
11521152

11531153
// *** 关键: 丢弃剩余的响应体 ***
11541154
const maxDiscardSize = 64 * 1024
11551155
discardErr := func() error { // 使用匿名函数捕获丢弃错误
1156-
_, err := copyb.CopyN(io.Discard, resp.Body, maxDiscardSize)
1156+
_, err := iox.CopyN(io.Discard, resp.Body, maxDiscardSize)
11571157
// 如果错误是 EOF,说明我们已经读完了或者超出了 maxDiscardSize,这不是一个需要报告的错误
11581158
if errors.Is(err, io.EOF) {
11591159
return nil

0 commit comments

Comments
 (0)