Deprecate ioutil

This commit is contained in:
andig 2021-02-22 08:11:00 +01:00
parent 88d6dcf23f
commit 171c6f59fd
4 changed files with 7 additions and 9 deletions

View file

@ -2,7 +2,7 @@ package charger
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"reflect"
"strings"
@ -59,7 +59,7 @@ func NewTestMobileConnect(t *testing.T, responses []apiResponse) *MobileConnect
return &http.Response{
StatusCode: 200,
// Send response to be tested
Body: ioutil.NopCloser(bytes.NewBufferString(responseString)),
Body: io.NopCloser(bytes.NewBufferString(responseString)),
// Must be set to non-nil value or it panics
Header: make(http.Header),
}

View file

@ -2,7 +2,7 @@ package detect
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
@ -94,7 +94,7 @@ func (h *HttpHandler) Test(log *util.Logger, ip string) []interface{} {
}
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil
}

View file

@ -2,7 +2,6 @@ package util
import (
"io"
"io/ioutil"
"log"
"os"
"regexp"
@ -43,7 +42,7 @@ func NewLogger(area string) *Logger {
}
level := LogLevelForArea(area)
notepad := jww.NewNotepad(level, level, os.Stdout, ioutil.Discard, padded, log.Ldate|log.Ltime)
notepad := jww.NewNotepad(level, level, os.Stdout, io.Discard, padded, log.Ldate|log.Ltime)
loggersMux.Lock()
defer loggersMux.Unlock()

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
)
@ -58,13 +57,13 @@ func (e StatusError) HasStatus(codes ...int) bool {
func ReadBody(resp *http.Response) ([]byte, error) {
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return []byte{}, err
}
// maintain body after reading
resp.Body = ioutil.NopCloser(bytes.NewBuffer(b))
resp.Body = io.NopCloser(bytes.NewBuffer(b))
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return b, StatusError{resp: resp}