chore: remove refs to deprecated io/ioutil

Signed-off-by: guoguangwu <guoguangwug@gmail.com>
This commit is contained in:
guoguangwu
2024-05-07 17:50:39 +08:00
committed by Ferdinand Mütsch
parent f2bffe025b
commit fd5bdf9920
7 changed files with 27 additions and 28 deletions

View File

@@ -14,7 +14,6 @@ import (
routeutils "github.com/muety/wakapi/routes/utils"
"github.com/patrickmn/go-cache"
"io"
"io/ioutil"
"net/http"
"time"
)
@@ -67,9 +66,9 @@ func (m *WakatimeRelayMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Reque
return
}
body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)
r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))
// prevent cycles
downstreamInstanceId := ownInstanceId
@@ -149,12 +148,12 @@ func (m *WakatimeRelayMiddleware) filterByCache(r *http.Request) error {
return err
}
body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)
r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))
var rawData interface{}
if err := json.NewDecoder(ioutil.NopCloser(bytes.NewBuffer(body))).Decode(&rawData); err != nil {
if err := json.NewDecoder(io.NopCloser(bytes.NewBuffer(body))).Decode(&rawData); err != nil {
return err
}
@@ -190,7 +189,7 @@ func (m *WakatimeRelayMiddleware) filterByCache(r *http.Request) error {
if err := json.NewEncoder(&buf).Encode(newData); err != nil {
return err
}
r.Body = ioutil.NopCloser(&buf)
r.Body = io.NopCloser(&buf)
return nil
}

View File

@@ -8,7 +8,7 @@ import (
"github.com/muety/wakapi/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"regexp"
@@ -69,7 +69,7 @@ func TestBadgeHandler_Get(t *testing.T) {
assert.Equal(t, http.StatusOK, res.StatusCode)
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("unextected error. Error: %s", err)
}
@@ -90,7 +90,7 @@ func TestBadgeHandler_Get(t *testing.T) {
assert.Equal(t, http.StatusForbidden, res.StatusCode)
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("unextected error. Error: %s", err)
}
@@ -110,7 +110,7 @@ func TestBadgeHandler_Get(t *testing.T) {
assert.Equal(t, http.StatusForbidden, res.StatusCode)
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("unextected error. Error: %s", err)
}

View File

@@ -8,7 +8,7 @@ import (
"github.com/muety/wakapi/middlewares"
"github.com/muety/wakapi/mocks"
"github.com/muety/wakapi/models"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@@ -78,7 +78,7 @@ func TestUsersHandler_Get(t *testing.T) {
res := rec.Result()
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("unexpected error. Error: %s", err)
}
@@ -104,7 +104,7 @@ func TestUsersHandler_Get(t *testing.T) {
res := rec.Result()
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("unextected error. Error: %s", err)
}
@@ -128,7 +128,7 @@ func TestUsersHandler_Get(t *testing.T) {
res := rec.Result()
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("unextected error. Error: %s", err)
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/muety/wakapi/mocks"
"github.com/muety/wakapi/models"
"github.com/stretchr/testify/assert"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
@@ -58,7 +58,7 @@ func TestHomeHandler_Get_NotLoggedIn(t *testing.T) {
assert.Equal(t, http.StatusOK, res.StatusCode)
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("unextected error. Error: %s", err)
}

View File

@@ -19,7 +19,7 @@ import (
stripePrice "github.com/stripe/stripe-go/v74/price"
stripeSubscription "github.com/stripe/stripe-go/v74/subscription"
"github.com/stripe/stripe-go/v74/webhook"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
@@ -197,7 +197,7 @@ func (h *SubscriptionHandler) PostPortal(w http.ResponseWriter, r *http.Request)
func (h *SubscriptionHandler) PostWebhook(w http.ResponseWriter, r *http.Request) {
bodyReader := http.MaxBytesReader(w, r.Body, int64(65536))
payload, err := ioutil.ReadAll(bodyReader)
payload, err := io.ReadAll(bodyReader)
if err != nil {
conf.Log().Request(r).Error("error in stripe webhook request: %v", err)
w.WriteHeader(http.StatusServiceUnavailable)

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"github.com/muety/wakapi/models"
"io/ioutil"
"io"
"net/http"
)
@@ -25,11 +25,11 @@ func ParseHeartbeats(r *http.Request) ([]*models.Heartbeat, error) {
func tryParseBulk(r *http.Request) ([]*models.Heartbeat, error) {
var heartbeats []*models.Heartbeat
body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)
r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))
dec := json.NewDecoder(ioutil.NopCloser(bytes.NewBuffer(body)))
dec := json.NewDecoder(io.NopCloser(bytes.NewBuffer(body)))
if err := dec.Decode(&heartbeats); err != nil {
return nil, err
}
@@ -40,11 +40,11 @@ func tryParseBulk(r *http.Request) ([]*models.Heartbeat, error) {
func tryParseSingle(r *http.Request) ([]*models.Heartbeat, error) {
var heartbeat models.Heartbeat
body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)
r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))
dec := json.NewDecoder(ioutil.NopCloser(bytes.NewBuffer(body)))
dec := json.NewDecoder(io.NopCloser(bytes.NewBuffer(body)))
if err := dec.Decode(&heartbeat); err != nil {
return nil, err
}

View File

@@ -3,8 +3,8 @@ package utils
import (
"encoding/json"
"html/template"
"io"
"io/fs"
"io/ioutil"
"path"
)
@@ -44,7 +44,7 @@ func LoadTemplates(templateFs fs.FS, funcs template.FuncMap) (TemplateMap, error
if err != nil {
return nil, err
}
templateData, err := ioutil.ReadAll(templateFile)
templateData, err := io.ReadAll(templateFile)
if err != nil {
return nil, err
}