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) { func closeBody(r *http.Response) {
if r.Body != nil { if r.Body != nil {
_, _ = io.Copy(ioutil.Discard, r.Body) _, _ = io.Copy(io.Discard, r.Body)
_ = r.Body.Close() _ = r.Body.Close()
} }
} }

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

@@ -5,7 +5,6 @@ package api4
import ( import (
"io" "io"
"io/ioutil"
"net/http" "net/http"
"github.com/mattermost/mattermost-server/v6/audit" "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) { 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 { 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) c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)

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

@@ -6,7 +6,6 @@ package api4
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"github.com/mattermost/mattermost-server/v6/app" "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) { 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 { if !*c.App.Config().ServiceSettings.EnableCustomEmoji {
c.Err = model.NewAppError("createEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented) c.Err = model.NewAppError("createEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)

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

@@ -6,7 +6,6 @@ package api4
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"time" "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) { 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() c.RequireUserId()
if c.Err != nil { if c.Err != nil {

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

@@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"path" "path"
"reflect" "reflect"
@@ -527,7 +526,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
defer func() { defer func() {
io.Copy(ioutil.Discard, res.Body) io.Copy(io.Discard, res.Body)
res.Body.Close() res.Body.Close()
}() }()

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

@@ -9,7 +9,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"regexp" "regexp"
"strconv" "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) { 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() c.RequireTeamId()
if c.Err != nil { if c.Err != nil {

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

@@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
"strings" "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) { 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() c.RequireUserId()
if c.Err != nil { 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) return model.NewAppError("testSiteURL", "app.admin.test_site_url.failure", nil, "", http.StatusBadRequest)
} }
defer func() { defer func() {
_, _ = io.Copy(ioutil.Discard, res.Body) _, _ = io.Copy(io.Discard, res.Body)
_ = res.Body.Close() _ = res.Body.Close()
}() }()

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

@@ -51,7 +51,7 @@ func (s *Server) downloadFromURL(downloadURL string) ([]byte, error) {
} }
if !(resp.StatusCode >= 200 && resp.StatusCode < 300) { if !(resp.StatusCode >= 200 && resp.StatusCode < 300) {
_, _ = io.Copy(ioutil.Discard, resp.Body) _, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close() _ = resp.Body.Close()
return errors.Errorf("failed to fetch from %s", downloadURL) return errors.Errorf("failed to fetch from %s", downloadURL)
} }

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

@@ -7,7 +7,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"runtime" "runtime"
"strings" "strings"
@@ -469,7 +468,7 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
// Reading the body to completion. // Reading the body to completion.
_, err = io.Copy(ioutil.Discard, resp.Body) _, err = io.Copy(io.Discard, resp.Body)
if err != nil { if err != nil {
return err return err
} }

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

@@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"image" "image"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"regexp" "regexp"
@@ -606,7 +605,7 @@ func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64,
if body != nil { if body != nil {
defer func() { defer func() {
io.Copy(ioutil.Discard, body) io.Copy(io.Discard, body)
body.Close() body.Close()
}() }()
} }

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

@@ -6,7 +6,6 @@ package slashcommands
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"path" "path"
"regexp" "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 return &model.CommandResponse{Text: "Unable to get file", ResponseType: model.CommandResponseTypeEphemeral}, err
} }
defer func() { defer func() {
io.Copy(ioutil.Discard, r.Body) io.Copy(io.Discard, r.Body)
r.Body.Close() 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) return &model.CommandResponse{Text: "Unable to get file", ResponseType: model.CommandResponseTypeEphemeral}, errors.Errorf("unexpected status code %d", r.StatusCode)
} }
defer func() { defer func() {
io.Copy(ioutil.Discard, r.Body) io.Copy(io.Discard, r.Body)
r.Body.Close() r.Body.Close()
}() }()

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

@@ -103,7 +103,7 @@ func (c *Client4) boolString(value bool) string {
func closeBody(r *http.Response) { func closeBody(r *http.Response) {
if r.Body != nil { if r.Body != nil {
_, _ = io.Copy(ioutil.Discard, r.Body) _, _ = io.Copy(io.Discard, r.Body)
_ = r.Body.Close() _ = r.Body.Close()
} }
} }

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

@@ -6,7 +6,6 @@ package marketplace
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@@ -114,7 +113,7 @@ func (c *Client) GetLatestPlugin(filter *model.MarketplacePluginFilter) (*model.
// closeBody ensures the Body of an http.Response is properly closed. // closeBody ensures the Body of an http.Response is properly closed.
func closeBody(r *http.Response) { func closeBody(r *http.Response) {
if r.Body != nil { if r.Body != nil {
_, _ = io.Copy(ioutil.Discard, r.Body) _, _ = io.Copy(io.Discard, r.Body)
_ = r.Body.Close() _ = r.Body.Close()
} }
} }

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

@@ -9,7 +9,6 @@ import (
"image/color" "image/color"
"image/png" "image/png"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"sync" "sync"
@@ -35,7 +34,7 @@ func TestService_sendProfileImageToRemote(t *testing.T) {
shouldError := &flag{} shouldError := &flag{}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 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() { if shouldError.get() {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)

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

@@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@@ -65,7 +64,7 @@ func GetMailBox(email string) (results JSONMessageHeaderInbucket, err error) {
} }
defer func() { defer func() {
io.Copy(ioutil.Discard, resp.Body) io.Copy(io.Discard, resp.Body)
resp.Body.Close() resp.Body.Close()
}() }()
@@ -99,7 +98,7 @@ func GetMessageFromMailbox(email, id string) (JSONMessageInbucket, error) {
return record, err return record, err
} }
defer func() { defer func() {
io.Copy(ioutil.Discard, emailResponse.Body) io.Copy(io.Discard, emailResponse.Body)
emailResponse.Body.Close() emailResponse.Body.Close()
}() }()