fix: use of ioutil package (#5261)

* fix ioutil.NopCloser

* fix ioutil.ReadAll

* fix ioutil.ReadFile

* fix ioutil.WriteFile

* run goimports -w -format-only ./

* update CHANGELOG.md
This commit is contained in:
Kota
2023-06-25 19:48:23 +09:00
committed by GitHub
parent a04bf251c7
commit 6f803ec9a9
26 changed files with 73 additions and 85 deletions

View File

@@ -17,7 +17,7 @@ package httplib
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
)
@@ -34,6 +34,6 @@ func NewHttpResponseWithJsonBody(data interface{}) *http.Response {
}
return &http.Response{
ContentLength: int64(len(body)),
Body: ioutil.NopCloser(bytes.NewReader(body)),
Body: io.NopCloser(bytes.NewReader(body)),
}
}

View File

@@ -37,7 +37,6 @@ import (
"encoding/json"
"encoding/xml"
"io"
"io/ioutil"
"mime/multipart"
"net"
"net/http"
@@ -283,16 +282,16 @@ func (b *BeegoHTTPRequest) Body(data interface{}) *BeegoHTTPRequest {
switch t := data.(type) {
case string:
bf := bytes.NewBufferString(t)
b.req.Body = ioutil.NopCloser(bf)
b.req.Body = io.NopCloser(bf)
b.req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(bf), nil
return io.NopCloser(bf), nil
}
b.req.ContentLength = int64(len(t))
case []byte:
bf := bytes.NewBuffer(t)
b.req.Body = ioutil.NopCloser(bf)
b.req.Body = io.NopCloser(bf)
b.req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(bf), nil
return io.NopCloser(bf), nil
}
b.req.ContentLength = int64(len(t))
default:
@@ -308,9 +307,9 @@ func (b *BeegoHTTPRequest) XMLBody(obj interface{}) (*BeegoHTTPRequest, error) {
if err != nil {
return b, berror.Wrap(err, InvalidXMLBody, "obj could not be converted to XML data")
}
b.req.Body = ioutil.NopCloser(bytes.NewReader(byts))
b.req.Body = io.NopCloser(bytes.NewReader(byts))
b.req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(byts)), nil
return io.NopCloser(bytes.NewReader(byts)), nil
}
b.req.ContentLength = int64(len(byts))
b.req.Header.Set(contentTypeKey, "application/xml")
@@ -325,7 +324,7 @@ func (b *BeegoHTTPRequest) YAMLBody(obj interface{}) (*BeegoHTTPRequest, error)
if err != nil {
return b, berror.Wrap(err, InvalidYAMLBody, "obj could not be converted to YAML data")
}
b.req.Body = ioutil.NopCloser(bytes.NewReader(byts))
b.req.Body = io.NopCloser(bytes.NewReader(byts))
b.req.ContentLength = int64(len(byts))
b.req.Header.Set(contentTypeKey, "application/x+yaml")
}
@@ -339,7 +338,7 @@ func (b *BeegoHTTPRequest) JSONBody(obj interface{}) (*BeegoHTTPRequest, error)
if err != nil {
return b, berror.Wrap(err, InvalidJSONBody, "obj could not be converted to JSON body")
}
b.req.Body = ioutil.NopCloser(bytes.NewReader(byts))
b.req.Body = io.NopCloser(bytes.NewReader(byts))
b.req.ContentLength = int64(len(byts))
b.req.Header.Set(contentTypeKey, "application/json")
}
@@ -400,7 +399,7 @@ func (b *BeegoHTTPRequest) handleFiles() {
_ = pw.Close()
}()
b.Header(contentTypeKey, bodyWriter.FormDataContentType())
b.req.Body = ioutil.NopCloser(pr)
b.req.Body = io.NopCloser(pr)
b.Header("Transfer-Encoding", "chunked")
}