Skip to content

Commit

Permalink
feature: support go version < 1.16 (#22)
Browse files Browse the repository at this point in the history
* upgrade package version to v1.0.13

* support go version < 1.16
  • Loading branch information
luxuze authored Jun 11, 2021
1 parent 632a0c2 commit 64f9f35
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
5 changes: 2 additions & 3 deletions benchmark/bechmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/tls"
"io"
"io/ioutil"
"net/http"
"net/http/httptrace"
"net/url"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (b *Work) makeRequest(c *http.Client) {
if err == nil {
size = resp.ContentLength
code = resp.StatusCode
io.Copy(ioutil.Discard, resp.Body)
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}
t := now()
Expand Down Expand Up @@ -262,7 +261,7 @@ func cloneRequest(r *http.Request, body []byte) *http.Request {
r2.Header[k] = append([]string(nil), s...)
}
if len(body) > 0 {
r2.Body = ioutil.NopCloser(bytes.NewReader(body))
r2.Body = io.NopCloser(bytes.NewReader(body))
}
return r2
}
Expand Down
16 changes: 8 additions & 8 deletions request/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/url"
"os"
"path"

"github.com/monaco-io/request/context"
Expand All @@ -25,7 +25,7 @@ func (b BodyString) Apply(ctx *context.Context) {
bBytes := bytes.NewReader([]byte(b.Data))
rc, ok := io.Reader(bBytes).(io.ReadCloser)
if !ok && bBytes != nil {
rc = ioutil.NopCloser(bBytes)
rc = io.NopCloser(bBytes)
}

ctx.Request.Body = rc
Expand Down Expand Up @@ -61,7 +61,7 @@ func (b BodyJSON) Apply(ctx *context.Context) {
}
}

ctx.Request.Body = ioutil.NopCloser(buf)
ctx.Request.Body = io.NopCloser(buf)
ctx.Request.ContentLength = int64(buf.Len())
ctx.SetContentType(context.JSON)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (b BodyXML) Apply(ctx *context.Context) {
}
}

ctx.Request.Body = ioutil.NopCloser(buf)
ctx.Request.Body = io.NopCloser(buf)
ctx.Request.ContentLength = int64(buf.Len())
ctx.SetContentType(context.XML)
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (b BodyYAML) Apply(ctx *context.Context) {
}
}

ctx.Request.Body = ioutil.NopCloser(buf)
ctx.Request.Body = io.NopCloser(buf)
ctx.Request.ContentLength = int64(buf.Len())
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func (b BodyURLEncodedForm) Apply(ctx *context.Context) {
return
}

ctx.Request.Body = ioutil.NopCloser(buf)
ctx.Request.Body = io.NopCloser(buf)
ctx.Request.ContentLength = int64(buf.Len())
ctx.SetContentType(context.URLEncodedForm)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func (fd BodyForm) Apply(ctx *context.Context) {
err = fmt.Errorf("cread form file failed: %s", err)
goto ErrorHandler
}
data, err = ioutil.ReadFile(filePath)
data, err = os.ReadFile(filePath)
if err != nil {
err = fmt.Errorf("read local file failed: %s", err)
goto ErrorHandler
Expand All @@ -238,7 +238,7 @@ func (fd BodyForm) Apply(ctx *context.Context) {
return
}

ctx.Request.Body = ioutil.NopCloser(&buf)
ctx.Request.Body = io.NopCloser(&buf)
ctx.Request.Header.Add("Content-Type", multipartWriter.FormDataContentType())
return

Expand Down
3 changes: 1 addition & 2 deletions response/reponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

Expand Down Expand Up @@ -43,7 +42,7 @@ func (s *Sugar) Close() *Sugar {
if s.ctx.HasError() {
return s
}
if _, err := io.Copy(ioutil.Discard, s.ctx.Response.Body); err != nil {
if _, err := io.Copy(io.Discard, s.ctx.Response.Body); err != nil {
s.ctx.SetError(err)
return s
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package request

// Version of module github.com/monaco-io/request
const Version = "v1.0.11"
const Version = "v1.0.14"

0 comments on commit 64f9f35

Please sign in to comment.