0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

all: remove deprecated use of io/ioutil

This commit is contained in:
Will Norris 2023-01-31 20:30:38 -08:00
parent 12d8f92d33
commit 5ffd8db241
6 changed files with 9 additions and 14 deletions

View file

@ -12,7 +12,6 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -65,7 +64,7 @@ func sign(key string, s string, urlOnly bool) ([]byte, error) {
func parseKey(s string) ([]byte, error) { func parseKey(s string) ([]byte, error) {
if strings.HasPrefix(s, "@") { if strings.HasPrefix(s, "@") {
return ioutil.ReadFile(s[1:]) return os.ReadFile(s[1:])
} }
return []byte(s), nil return []byte(s), nil
} }

View file

@ -4,7 +4,7 @@
package main package main
import ( import (
"io/ioutil" "io"
"net/url" "net/url"
"os" "os"
"reflect" "reflect"
@ -25,7 +25,7 @@ func TestMainFunc(t *testing.T) {
main() main()
w.Close() w.Close()
output, err := ioutil.ReadAll(r) output, err := io.ReadAll(r)
got := string(output) got := string(output)
if err != nil { if err != nil {
t.Errorf("error reading from pipe: %v", err) t.Errorf("error reading from pipe: %v", err)
@ -94,7 +94,7 @@ func TestParseKey(t *testing.T) {
} }
func TestParseKey_FilePath(t *testing.T) { func TestParseKey_FilePath(t *testing.T) {
f, err := ioutil.TempFile("", "key") f, err := os.CreateTemp("", "key")
if err != nil { if err != nil {
t.Errorf("error creating temp file: %v", err) t.Errorf("error creating temp file: %v", err)
} }

View file

@ -7,7 +7,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
@ -118,7 +117,7 @@ func (skl *signatureKeyList) Set(value string) error {
if strings.HasPrefix(v, "@") { if strings.HasPrefix(v, "@") {
file := strings.TrimPrefix(v, "@") file := strings.TrimPrefix(v, "@")
var err error var err error
key, err = ioutil.ReadFile(file) key, err = os.ReadFile(file)
if err != nil { if err != nil {
log.Fatalf("error reading signature file: %v", err) log.Fatalf("error reading signature file: %v", err)
} }

View file

@ -14,7 +14,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"mime" "mime"
"net" "net"
@ -242,7 +241,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
if contentType == "" || contentType == "application/octet-stream" || contentType == "binary/octet-stream" { if contentType == "" || contentType == "application/octet-stream" || contentType == "binary/octet-stream" {
// try to detect content type // try to detect content type
b := bufio.NewReader(resp.Body) b := bufio.NewReader(resp.Body)
resp.Body = ioutil.NopCloser(b) resp.Body = io.NopCloser(b)
contentType = peekContentType(b) contentType = peekContentType(b)
} }
if resp.ContentLength != 0 && !contentTypeMatches(p.ContentTypes, contentType) { if resp.ContentLength != 0 && !contentTypeMatches(p.ContentTypes, contentType) {
@ -497,7 +496,7 @@ func (t *TransformingTransport) RoundTrip(req *http.Request) (*http.Response, er
return &http.Response{StatusCode: http.StatusNotModified}, nil return &http.Response{StatusCode: http.StatusNotModified}, nil
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -11,7 +11,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"io" "io"
"io/ioutil"
"log" "log"
"path" "path"
@ -35,7 +34,7 @@ func (c *cache) Get(key string) ([]byte, bool) {
} }
defer r.Close() defer r.Close()
value, err := ioutil.ReadAll(r) value, err := io.ReadAll(r)
if err != nil { if err != nil {
log.Printf("error reading from gcs: %v", err) log.Printf("error reading from gcs: %v", err)
return nil, false return nil, false

View file

@ -11,7 +11,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"io" "io"
"io/ioutil"
"log" "log"
"net/url" "net/url"
"path" "path"
@ -44,7 +43,7 @@ func (c *cache) Get(key string) ([]byte, bool) {
return nil, false return nil, false
} }
value, err := ioutil.ReadAll(resp.Body) value, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Printf("error reading s3 response body: %v", err) log.Printf("error reading s3 response body: %v", err)
return nil, false return nil, false