Replace ioutil.Discard with io.Discard (#20707)

Этот коммит содержится в:
Tim Scheuermann
2022-07-27 12:40:33 +03:00
коммит произвёл GitHub
родитель c00609ab8e
Коммит eba08cbb11
16 изменённых файлов: 18 добавлений и 30 удалений

Просмотреть файл

@@ -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()
}
}

Просмотреть файл

@@ -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)

Просмотреть файл

@@ -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)

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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()
}()

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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()
}()

Просмотреть файл

@@ -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)
}

Просмотреть файл

@@ -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
}

Просмотреть файл

@@ -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()
}()
}

Просмотреть файл

@@ -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()
}()

Просмотреть файл

@@ -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()
}
}

Просмотреть файл

@@ -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()
}
}

Просмотреть файл

@@ -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)

Просмотреть файл

@@ -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()
}()