refactor: replace ioutil.ReadAll with io.ReadAll (#7200)

This commit is contained in:
Joe Chen 2022-10-22 21:34:53 +08:00 committed by GitHub
parent b9f5cfddc1
commit 11edc09681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 18 deletions

View File

@ -10,7 +10,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "io"
"net/url" "net/url"
"strings" "strings"
"time" "time"
@ -775,7 +775,7 @@ func (t *HookTask) deliver() {
t.ResponseInfo.Headers[k] = strings.Join(vals, ",") t.ResponseInfo.Headers[k] = strings.Join(vals, ",")
} }
p, err := ioutil.ReadAll(resp.Body) p, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.ResponseInfo.Body = fmt.Sprintf("read body: %s", err) t.ResponseInfo.Body = fmt.Sprintf("read body: %s", err)
return return

View File

@ -7,7 +7,6 @@ package lfs
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -133,7 +132,7 @@ func Test_basicHandler_serveDownload(t *testing.T) {
assert.Equal(t, test.expStatusCode, resp.StatusCode) assert.Equal(t, test.expStatusCode, resp.StatusCode)
assert.Equal(t, test.expHeader, resp.Header) assert.Equal(t, test.expHeader, resp.Header)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -199,7 +198,7 @@ func Test_basicHandler_serveUpload(t *testing.T) {
resp := rr.Result() resp := rr.Result()
assert.Equal(t, test.expStatusCode, resp.StatusCode) assert.Equal(t, test.expStatusCode, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -280,7 +279,7 @@ func Test_basicHandler_serveVerify(t *testing.T) {
resp := rr.Result() resp := rr.Result()
assert.Equal(t, test.expStatusCode, resp.StatusCode) assert.Equal(t, test.expStatusCode, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -7,7 +7,7 @@ package lfs
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -138,7 +138,7 @@ func Test_serveBatch(t *testing.T) {
resp := rr.Result() resp := rr.Result()
assert.Equal(t, test.expStatusCode, resp.StatusCode) assert.Equal(t, test.expStatusCode, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -7,7 +7,7 @@ package lfs
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -24,7 +24,7 @@ func Test_authenticate(t *testing.T) {
m := macaron.New() m := macaron.New()
m.Use(macaron.Renderer()) m.Use(macaron.Renderer())
m.Get("/", authenticate(), func(w http.ResponseWriter, user *db.User) { m.Get("/", authenticate(), func(w http.ResponseWriter, user *db.User) {
fmt.Fprintf(w, "ID: %d, Name: %s", user.ID, user.Name) _, _ = fmt.Fprintf(w, "ID: %d, Name: %s", user.ID, user.Name)
}) })
tests := []struct { tests := []struct {
@ -178,7 +178,7 @@ func Test_authenticate(t *testing.T) {
assert.Equal(t, test.expStatusCode, resp.StatusCode) assert.Equal(t, test.expStatusCode, resp.StatusCode)
assert.Equal(t, test.expHeader, resp.Header) assert.Equal(t, test.expHeader, resp.Header)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -311,7 +311,7 @@ func Test_authorize(t *testing.T) {
resp := rr.Result() resp := rr.Result()
assert.Equal(t, test.expStatusCode, resp.StatusCode) assert.Equal(t, test.expStatusCode, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -402,7 +402,7 @@ func Test_verifyOID(t *testing.T) {
resp := rr.Result() resp := rr.Result()
assert.Equal(t, test.expStatusCode, resp.StatusCode) assert.Equal(t, test.expStatusCode, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -418,7 +418,7 @@ func Test_internalServerError(t *testing.T) {
resp := rr.Result() resp := rr.Result()
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -6,7 +6,7 @@ package repo
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"strings" "strings"
"time" "time"
@ -339,7 +339,7 @@ func UpdateAvatarSetting(c *context.Context, f form.Avatar, ctxRepo *db.Reposito
} }
defer r.Close() defer r.Close()
data, err := ioutil.ReadAll(r) data, err := io.ReadAll(r)
if err != nil { if err != nil {
return fmt.Errorf("read avatar content: %v", err) return fmt.Errorf("read avatar content: %v", err)
} }

View File

@ -10,7 +10,7 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"image/png" "image/png"
"io/ioutil" "io"
"strings" "strings"
"github.com/pquerna/otp" "github.com/pquerna/otp"
@ -132,7 +132,7 @@ func UpdateAvatarSetting(c *context.Context, f form.Avatar, ctxUser *db.User) er
_ = r.Close() _ = r.Close()
}() }()
data, err := ioutil.ReadAll(r) data, err := io.ReadAll(r)
if err != nil { if err != nil {
return fmt.Errorf("read avatar content: %v", err) return fmt.Errorf("read avatar content: %v", err)
} }