cmd,internal: replace deprecated ioutil with io and os

Change-Id: I1d66a5c7b087d9329628efb6ce8849a004663b51
Reviewed-on: https://go-review.googlesource.com/c/website/+/592895
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Oleksandr Redko 2024-06-15 16:02:39 +03:00 коммит произвёл Gopher Robot
Родитель 8d335a83f6
Коммит c9f9352637
10 изменённых файлов: 19 добавлений и 24 удалений

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

@ -18,7 +18,6 @@ import (
"html/template"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
"net/url"
@ -811,7 +810,7 @@ func (s *seekableFS) Open(name string) (fs.File, error) {
if info.IsDir() {
return f, nil
}
data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
f.Close()
return nil, err

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

@ -11,7 +11,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"strings"
)
@ -42,7 +41,7 @@ func (r *Repo) handshake() error {
if err != nil {
return fmt.Errorf("handshake: %v", err)
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if resp.StatusCode != 200 {
return fmt.Errorf("handshake: %v\n%s", resp.Status, data)
}
@ -130,7 +129,7 @@ func (r *Repo) refs(prefixes ...string) ([]ref, error) {
return nil, fmt.Errorf("refs: %v", err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if resp.StatusCode != 200 {
return nil, fmt.Errorf("refs: %v\n%s", resp.Status, data)
}
@ -222,7 +221,7 @@ func (r *Repo) fetch(h Hash) (fs.FS, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
data, _ := ioutil.ReadAll(resp.Body)
data, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("fetch: %v\n%s\n%s", resp.Status, data, hex.Dump(postbody))
}
if ct := resp.Header.Get("Content-Type"); ct != "application/x-git-upload-pack-result" {

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

@ -6,7 +6,7 @@ package gitfs
import (
"io/fs"
"io/ioutil"
"os"
"testing"
)
@ -49,7 +49,7 @@ func TestGitHub(t *testing.T) {
}
func TestPack(t *testing.T) {
data, err := ioutil.ReadFile("testdata/scratch.pack")
data, err := os.ReadFile("testdata/scratch.pack")
if err != nil {
t.Fatal(err)
}

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

@ -10,7 +10,7 @@ import (
"crypto/sha1"
"encoding/binary"
"fmt"
"io/ioutil"
"io"
)
// unpack parses data, which is a Git pack-formatted archive,
@ -142,7 +142,7 @@ func unpackObject(s *store, objs []byte, off int) (typ objType, h Hash, content
if err != nil {
return fail(fmt.Errorf("invalid object deflate: %v", err))
}
data, err := ioutil.ReadAll(zr)
data, err := io.ReadAll(zr)
if err != nil {
return fail(fmt.Errorf("invalid object: bad deflate: %v", err))
}

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

@ -17,7 +17,6 @@ import (
"go/token"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
"net/url"
@ -181,7 +180,7 @@ func (d *docs) open(dir string, mode mode, goos, goarch string) *Page {
if err != nil {
return nil, err
}
return ioutil.NopCloser(bytes.NewReader(data)), nil
return io.NopCloser(bytes.NewReader(data)), nil
}
// Make the syscall/js package always visible by default.

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

@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"regexp"
@ -117,7 +116,7 @@ func makeCompileRequest(ctx context.Context, backend string, req *Request, res *
defer r.Body.Close()
if r.StatusCode != http.StatusOK {
b, _ := ioutil.ReadAll(r.Body)
b, _ := io.ReadAll(r.Body)
return fmt.Errorf("bad status: %v body:\n%s", r.Status, b)
}

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

@ -123,7 +123,6 @@ import (
"image/png"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
"net/url"
@ -742,9 +741,9 @@ func (tc *testcase) screenshot(ctx context.Context, url, file string,
return nil, fmt.Errorf("object.NewReader(ctx): %w", err)
} else if err == nil {
defer r.Close()
data, err = ioutil.ReadAll(r)
data, err = io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("ioutil.ReadAll(...): %w", err)
return nil, fmt.Errorf("io.ReadAll(...): %w", err)
}
}
} else if cache {

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

@ -82,7 +82,7 @@ package tmplfunc
import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -234,7 +234,7 @@ func MustParseGlob(t Template, pattern string) {
func readFileOS(file string) (name string, b []byte, err error) {
name = filepath.Base(file)
b, err = ioutil.ReadFile(file)
b, err = os.ReadFile(file)
return
}

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

@ -153,10 +153,10 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
@ -244,7 +244,7 @@ func test(t *testing.T, glob string, do func(*case_) error) {
}
for _, file := range files {
t.Run(filepath.Base(file), func(t *testing.T) {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
}
@ -345,7 +345,7 @@ func (c *case_) runServer(addr string) error {
if err != nil {
return fmt.Errorf("%s:%d: %s %s: %s", c.file, c.line, c.method, c.url, err)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return fmt.Errorf("%s:%d: %s %s: reading body: %s", c.file, c.line, c.method, c.url, err)

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

@ -6,8 +6,8 @@ package webtest
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
@ -43,7 +43,7 @@ func testWebtest(t *testing.T, glob string, do func(*case_) error) {
}
for _, file := range files {
t.Run(filepath.Base(file), func(t *testing.T) {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
}