From db30c8384d2f9ccd4a9837c03ae93747e909fd1f Mon Sep 17 00:00:00 2001 From: ffranr Date: Fri, 27 Jan 2023 13:14:05 +0000 Subject: [PATCH] lint: remove depreciated io/ioutil As of Go 1.16, functionality provided in io/ioutil has been depreciated in favour of the io or os packages. Now that Go has been upgraded in go.mod, the linter will not pass without these changes. --- aperture.go | 3 +-- hashmail_server.go | 3 +-- lsat/store.go | 9 ++++----- lsat/store_test.go | 3 +-- proxy/proxy.go | 4 ++-- proxy/proxy_test.go | 8 ++++---- proxy/service.go | 4 ++-- secrets_test.go | 3 +-- 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/aperture.go b/aperture.go index 86e6ed8..56d3587 100644 --- a/aperture.go +++ b/aperture.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -414,7 +413,7 @@ func getConfig() (*Config, error) { // Read our config file, either from the custom path provided or our // default location. - b, err := ioutil.ReadFile(configFile) + b, err := os.ReadFile(configFile) switch { // If the file was found, unmarshal it. case err == nil: diff --git a/hashmail_server.go b/hashmail_server.go index cf41353..5f14ff0 100644 --- a/hashmail_server.go +++ b/hashmail_server.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "sync" "time" @@ -100,7 +99,7 @@ func (r *readStream) ReadNextMsg(ctx context.Context) ([]byte, error) { // reader, then read all the encoded bytes until the EOF is emitted by // the reader. msgReader := io.LimitReader(reader, int64(msgLen)) - return ioutil.ReadAll(msgReader) + return io.ReadAll(msgReader) } // ReturnStream gives up the read stream by passing it back up through the diff --git a/lsat/store.go b/lsat/store.go index 11c028d..736e19f 100644 --- a/lsat/store.go +++ b/lsat/store.go @@ -3,7 +3,6 @@ package lsat import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -113,7 +112,7 @@ func (f *FileStore) AllTokens() (map[string]*Token, error) { // just one token, either pending or paid. // TODO(guggero): Update comment once tokens expire and we keep backups. tokenDir := filepath.Dir(f.fileName) - files, err := ioutil.ReadDir(tokenDir) + files, err := os.ReadDir(tokenDir) if err != nil { return nil, err } @@ -156,7 +155,7 @@ func (f *FileStore) StoreToken(newToken *Token) error { if newToken.isPending() { newFileName = f.fileNamePending } - return ioutil.WriteFile(newFileName, bytes, 0600) + return os.WriteFile(newFileName, bytes, 0600) // Fail on any other error. case err != nil: @@ -173,7 +172,7 @@ func (f *FileStore) StoreToken(newToken *Token) error { // Write the new token first, so we still have the pending // around if something goes wrong. - err := ioutil.WriteFile(f.fileName, bytes, 0600) + err := os.WriteFile(f.fileName, bytes, 0600) if err != nil { return err } @@ -206,7 +205,7 @@ func (f *FileStore) RemovePendingToken() error { // readTokenFile reads a single token from a file and returns it deserialized. func readTokenFile(tokenFile string) (*Token, error) { - bytes, err := ioutil.ReadFile(tokenFile) + bytes, err := os.ReadFile(tokenFile) if err != nil { return nil, err } diff --git a/lsat/store_test.go b/lsat/store_test.go index 101021c..0c80a3c 100644 --- a/lsat/store_test.go +++ b/lsat/store_test.go @@ -1,7 +1,6 @@ package lsat import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -13,7 +12,7 @@ import ( func TestFileStore(t *testing.T) { t.Parallel() - tempDirName, err := ioutil.TempDir("", "lsatstore") + tempDirName, err := os.MkdirTemp("", "lsatstore") if err != nil { t.Fatal(err) } diff --git a/proxy/proxy.go b/proxy/proxy.go index 96ca926..ae2352b 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -4,9 +4,9 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" "net/http" "net/http/httputil" + "os" "regexp" "strconv" "strings" @@ -329,7 +329,7 @@ func certPool(services []*Service) (*x509.CertPool, error) { continue } - b, err := ioutil.ReadFile(service.TLSCertPath) + b, err := os.ReadFile(service.TLSCertPath) if err != nil { return nil, err } diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index b326c42..8b2e8fd 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -6,9 +6,9 @@ import ( "crypto/x509" "fmt" "io" - "io/ioutil" "net" "net/http" + "os" "path" "strings" "testing" @@ -169,7 +169,7 @@ func runHTTPTest(t *testing.T, tc *testCase) { // Ensure that we got the response body we expect. defer closeOrFail(t, resp.Body) - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) require.NoError(t, err) require.Equal(t, testHTTPResponseBody, string(bodyBytes)) @@ -188,7 +188,7 @@ func runHTTPTest(t *testing.T, tc *testCase) { // Ensure that we got the response body we expect. defer closeOrFail(t, resp.Body) - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) require.NoError(t, err) require.Equal(t, testHTTPResponseBody, string(bodyBytes)) @@ -237,7 +237,7 @@ func TestProxyGRPC(t *testing.T) { func runGRPCTest(t *testing.T, tc *testCase) { // Since gRPC only really works over TLS, we need to generate a // certificate and key pair first. - tempDirName, err := ioutil.TempDir("", "proxytest") + tempDirName, err := os.MkdirTemp("", "proxytest") require.NoError(t, err) certFile := path.Join(tempDirName, "proxy.cert") keyFile := path.Join(tempDirName, "proxy.key") diff --git a/proxy/service.go b/proxy/service.go index 559caa7..11651b6 100644 --- a/proxy/service.go +++ b/proxy/service.go @@ -4,8 +4,8 @@ import ( "encoding/base64" "encoding/hex" "fmt" - "io/ioutil" "net/http" + "os" "regexp" "strings" @@ -154,7 +154,7 @@ func prepareServices(services []*Service) error { "must be '!file+hex:path'") } prefix, fileName := parts[0], parts[1] - bytes, err := ioutil.ReadFile(fileName) + bytes, err := os.ReadFile(fileName) if err != nil { return err } diff --git a/secrets_test.go b/secrets_test.go index 62c6c2e..3c213a2 100644 --- a/secrets_test.go +++ b/secrets_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "crypto/sha256" - "io/ioutil" "net/url" "os" "testing" @@ -22,7 +21,7 @@ import ( func etcdSetup(t *testing.T) (*clientv3.Client, func()) { t.Helper() - tempDir, err := ioutil.TempDir("", "etcd") + tempDir, err := os.MkdirTemp("", "etcd") if err != nil { t.Fatalf("unable to create temp dir: %v", err) }