Replace deprecated ioutil with io and os (#20776)

* Replace ioutil with io and os

* Replace ioutil in utils/file.go

* Minor fix to tests and excluded files

Co-authored-by: Tim Scheuermann <tim.scheuermann@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Tim Scheuermann
2022-08-09 14:25:46 +03:00
коммит произвёл GitHub
родитель 15b6046a62
Коммит b4570afa90
115 изменённых файлов: 408 добавлений и 475 удалений

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

@@ -4,7 +4,7 @@
package imageproxy
import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@@ -85,7 +85,7 @@ func TestAtmosCamoBackend_GetImageDirect(t *testing.T) {
assert.Equal(t, "image/png", contentType)
require.NotNil(t, body)
respBody, _ := ioutil.ReadAll(body)
respBody, _ := io.ReadAll(body)
assert.Equal(t, []byte("1111111111"), respBody)
}

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

@@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime"
"net"
"net/http"
@@ -134,7 +133,7 @@ func (backend *LocalBackend) GetImageDirect(imageURL string) (io.ReadCloser, str
return nil, "", ErrLocalRequestFailed
}
return ioutil.NopCloser(recorder.Body), recorder.Header().Get("Content-Type"), nil
return io.NopCloser(recorder.Body), recorder.Header().Get("Content-Type"), nil
}
func (backend *LocalBackend) ServeImage(w http.ResponseWriter, req *http.Request) {
@@ -176,7 +175,7 @@ func (backend *LocalBackend) ServeImage(w http.ResponseWriter, req *http.Request
if contentType == "" || contentType == "application/octet-stream" || contentType == "binary/octet-stream" {
// try to detect content type
b := bufio.NewReader(resp.Body)
resp.Body = ioutil.NopCloser(b)
resp.Body = io.NopCloser(b)
contentType = peekContentType(b)
}
if resp.ContentLength != 0 && !contentTypeMatches(imageContentTypes, contentType) {

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

@@ -4,7 +4,7 @@
package imageproxy
import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
@@ -60,7 +60,7 @@ func TestLocalBackend_GetImage(t *testing.T) {
assert.Equal(t, "max-age=2592000, private", resp.Header.Get("Cache-Control"))
assert.Equal(t, "10", resp.Header.Get("Content-Length"))
respBody, _ := ioutil.ReadAll(resp.Body)
respBody, _ := io.ReadAll(resp.Body)
assert.Equal(t, []byte("1111111111"), respBody)
})
@@ -190,7 +190,7 @@ func TestLocalBackend_GetImage(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "attachment;filename=\"test.svg\"", resp.Header.Get("Content-Disposition"))
_, err = ioutil.ReadAll(resp.Body)
_, err = io.ReadAll(resp.Body)
require.NoError(t, err)
})
@@ -247,7 +247,7 @@ func TestLocalBackend_GetImageDirect(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "image/png", contentType)
respBody, _ := ioutil.ReadAll(body)
respBody, _ := io.ReadAll(body)
assert.Equal(t, []byte("1111111111"), respBody)
})