From eba08cbb118fd2aa41a725850bb16d935c8aae5b Mon Sep 17 00:00:00 2001 From: Tim Scheuermann Date: Wed, 27 Jul 2022 12:40:33 +0300 Subject: [PATCH] Replace ioutil.Discard with io.Discard (#20707) --- api4/apitestlib.go | 2 +- api4/brand.go | 3 +-- api4/emoji.go | 3 +-- api4/remote_cluster.go | 3 +-- api4/system.go | 3 +-- api4/team.go | 3 +-- api4/user.go | 3 +-- app/admin.go | 2 +- app/download.go | 2 +- app/notification_push.go | 3 +-- app/post_metadata.go | 3 +-- app/slashcommands/command_loadtest.go | 5 ++--- model/client4.go | 2 +- services/marketplace/client.go | 3 +-- services/remotecluster/sendprofileImage_test.go | 3 +-- shared/mail/inbucket.go | 5 ++--- 16 files changed, 18 insertions(+), 30 deletions(-) diff --git a/api4/apitestlib.go b/api4/apitestlib.go index 08c53286ac..9f2a91037d 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -381,7 +381,7 @@ func (th *TestHelper) TearDown() { func closeBody(r *http.Response) { if r.Body != nil { - _, _ = io.Copy(ioutil.Discard, r.Body) + _, _ = io.Copy(io.Discard, r.Body) _ = r.Body.Close() } } diff --git a/api4/brand.go b/api4/brand.go index 2903b5e289..0653c1f7f6 100644 --- a/api4/brand.go +++ b/api4/brand.go @@ -5,7 +5,6 @@ package api4 import ( "io" - "io/ioutil" "net/http" "github.com/mattermost/mattermost-server/v6/audit" @@ -33,7 +32,7 @@ func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { } func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { - defer io.Copy(ioutil.Discard, r.Body) + defer io.Copy(io.Discard, r.Body) if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize { c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge) diff --git a/api4/emoji.go b/api4/emoji.go index c7d15962c8..95fb682aae 100644 --- a/api4/emoji.go +++ b/api4/emoji.go @@ -6,7 +6,6 @@ package api4 import ( "encoding/json" "io" - "io/ioutil" "net/http" "github.com/mattermost/mattermost-server/v6/app" @@ -32,7 +31,7 @@ func (api *API) InitEmoji() { } func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) { - defer io.Copy(ioutil.Discard, r.Body) + defer io.Copy(io.Discard, r.Body) if !*c.App.Config().ServiceSettings.EnableCustomEmoji { c.Err = model.NewAppError("createEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented) diff --git a/api4/remote_cluster.go b/api4/remote_cluster.go index f05889b60f..a919beadb4 100644 --- a/api4/remote_cluster.go +++ b/api4/remote_cluster.go @@ -6,7 +6,6 @@ package api4 import ( "encoding/json" "io" - "io/ioutil" "net/http" "time" @@ -222,7 +221,7 @@ func uploadRemoteData(c *Context, w http.ResponseWriter, r *http.Request) { } func remoteSetProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { - defer io.Copy(ioutil.Discard, r.Body) + defer io.Copy(io.Discard, r.Body) c.RequireUserId() if c.Err != nil { diff --git a/api4/system.go b/api4/system.go index 09b765d8e7..2617ed03e5 100644 --- a/api4/system.go +++ b/api4/system.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "path" "reflect" @@ -527,7 +526,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) { return } defer func() { - io.Copy(ioutil.Discard, res.Body) + io.Copy(io.Discard, res.Body) res.Body.Close() }() diff --git a/api4/team.go b/api4/team.go index beb71703a4..33ede5115b 100644 --- a/api4/team.go +++ b/api4/team.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "regexp" "strconv" @@ -1610,7 +1609,7 @@ func getTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) { } func setTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) { - defer io.Copy(ioutil.Discard, r.Body) + defer io.Copy(io.Discard, r.Body) c.RequireTeamId() if c.Err != nil { diff --git a/api4/user.go b/api4/user.go index 6eee9d8db3..60145829fc 100644 --- a/api4/user.go +++ b/api4/user.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "strconv" "strings" @@ -419,7 +418,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { } func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { - defer io.Copy(ioutil.Discard, r.Body) + defer io.Copy(io.Discard, r.Body) c.RequireUserId() if c.Err != nil { diff --git a/app/admin.go b/app/admin.go index f7e681baf3..890a0d7d89 100644 --- a/app/admin.go +++ b/app/admin.go @@ -200,7 +200,7 @@ func (a *App) TestSiteURL(siteURL string) *model.AppError { return model.NewAppError("testSiteURL", "app.admin.test_site_url.failure", nil, "", http.StatusBadRequest) } defer func() { - _, _ = io.Copy(ioutil.Discard, res.Body) + _, _ = io.Copy(io.Discard, res.Body) _ = res.Body.Close() }() diff --git a/app/download.go b/app/download.go index e1a8ae0e58..ac9ac68466 100644 --- a/app/download.go +++ b/app/download.go @@ -51,7 +51,7 @@ func (s *Server) downloadFromURL(downloadURL string) ([]byte, error) { } if !(resp.StatusCode >= 200 && resp.StatusCode < 300) { - _, _ = io.Copy(ioutil.Discard, resp.Body) + _, _ = io.Copy(io.Discard, resp.Body) _ = resp.Body.Close() return errors.Errorf("failed to fetch from %s", downloadURL) } diff --git a/app/notification_push.go b/app/notification_push.go index d7c2232253..e10b716c7d 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -7,7 +7,6 @@ import ( "bytes" "encoding/json" "io" - "io/ioutil" "net/http" "runtime" "strings" @@ -469,7 +468,7 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error { } defer resp.Body.Close() // Reading the body to completion. - _, err = io.Copy(ioutil.Discard, resp.Body) + _, err = io.Copy(io.Discard, resp.Body) if err != nil { return err } diff --git a/app/post_metadata.go b/app/post_metadata.go index cbc920d506..05996e9b0a 100644 --- a/app/post_metadata.go +++ b/app/post_metadata.go @@ -8,7 +8,6 @@ import ( "fmt" "image" "io" - "io/ioutil" "net/http" "net/url" "regexp" @@ -606,7 +605,7 @@ func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64, if body != nil { defer func() { - io.Copy(ioutil.Discard, body) + io.Copy(io.Discard, body) body.Close() }() } diff --git a/app/slashcommands/command_loadtest.go b/app/slashcommands/command_loadtest.go index f92e1895af..3fcf0d1037 100644 --- a/app/slashcommands/command_loadtest.go +++ b/app/slashcommands/command_loadtest.go @@ -6,7 +6,6 @@ package slashcommands import ( "encoding/json" "io" - "io/ioutil" "net/http" "path" "regexp" @@ -507,7 +506,7 @@ func (*LoadTestProvider) URLCommand(a *app.App, c *request.Context, args *model. return &model.CommandResponse{Text: "Unable to get file", ResponseType: model.CommandResponseTypeEphemeral}, err } defer func() { - io.Copy(ioutil.Discard, r.Body) + io.Copy(io.Discard, r.Body) r.Body.Close() }() @@ -565,7 +564,7 @@ func (*LoadTestProvider) JsonCommand(a *app.App, c *request.Context, args *model return &model.CommandResponse{Text: "Unable to get file", ResponseType: model.CommandResponseTypeEphemeral}, errors.Errorf("unexpected status code %d", r.StatusCode) } defer func() { - io.Copy(ioutil.Discard, r.Body) + io.Copy(io.Discard, r.Body) r.Body.Close() }() diff --git a/model/client4.go b/model/client4.go index 98cd3c739e..2ce96173ef 100644 --- a/model/client4.go +++ b/model/client4.go @@ -103,7 +103,7 @@ func (c *Client4) boolString(value bool) string { func closeBody(r *http.Response) { if r.Body != nil { - _, _ = io.Copy(ioutil.Discard, r.Body) + _, _ = io.Copy(io.Discard, r.Body) _ = r.Body.Close() } } diff --git a/services/marketplace/client.go b/services/marketplace/client.go index e64f343fe8..4c179bd95d 100644 --- a/services/marketplace/client.go +++ b/services/marketplace/client.go @@ -6,7 +6,6 @@ package marketplace import ( "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -114,7 +113,7 @@ func (c *Client) GetLatestPlugin(filter *model.MarketplacePluginFilter) (*model. // closeBody ensures the Body of an http.Response is properly closed. func closeBody(r *http.Response) { if r.Body != nil { - _, _ = io.Copy(ioutil.Discard, r.Body) + _, _ = io.Copy(io.Discard, r.Body) _ = r.Body.Close() } } diff --git a/services/remotecluster/sendprofileImage_test.go b/services/remotecluster/sendprofileImage_test.go index a2249fd58a..48e7b3301f 100644 --- a/services/remotecluster/sendprofileImage_test.go +++ b/services/remotecluster/sendprofileImage_test.go @@ -9,7 +9,6 @@ import ( "image/color" "image/png" "io" - "io/ioutil" "net/http" "net/http/httptest" "sync" @@ -35,7 +34,7 @@ func TestService_sendProfileImageToRemote(t *testing.T) { shouldError := &flag{} ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - defer io.Copy(ioutil.Discard, r.Body) + defer io.Copy(io.Discard, r.Body) if shouldError.get() { w.WriteHeader(http.StatusInternalServerError) diff --git a/shared/mail/inbucket.go b/shared/mail/inbucket.go index b105a8899e..42805f69a6 100644 --- a/shared/mail/inbucket.go +++ b/shared/mail/inbucket.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" "strings" @@ -65,7 +64,7 @@ func GetMailBox(email string) (results JSONMessageHeaderInbucket, err error) { } defer func() { - io.Copy(ioutil.Discard, resp.Body) + io.Copy(io.Discard, resp.Body) resp.Body.Close() }() @@ -99,7 +98,7 @@ func GetMessageFromMailbox(email, id string) (JSONMessageInbucket, error) { return record, err } defer func() { - io.Copy(ioutil.Discard, emailResponse.Body) + io.Copy(io.Discard, emailResponse.Body) emailResponse.Body.Close() }()