Skip to content

Commit db30c83

Browse files
committed
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.
1 parent 73ed7bf commit db30c83

File tree

8 files changed

+16
-21
lines changed

8 files changed

+16
-21
lines changed

aperture.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"net/http"
1110
"os"
1211
"path/filepath"
@@ -414,7 +413,7 @@ func getConfig() (*Config, error) {
414413

415414
// Read our config file, either from the custom path provided or our
416415
// default location.
417-
b, err := ioutil.ReadFile(configFile)
416+
b, err := os.ReadFile(configFile)
418417
switch {
419418
// If the file was found, unmarshal it.
420419
case err == nil:

hashmail_server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"sync"
109
"time"
1110

@@ -100,7 +99,7 @@ func (r *readStream) ReadNextMsg(ctx context.Context) ([]byte, error) {
10099
// reader, then read all the encoded bytes until the EOF is emitted by
101100
// the reader.
102101
msgReader := io.LimitReader(reader, int64(msgLen))
103-
return ioutil.ReadAll(msgReader)
102+
return io.ReadAll(msgReader)
104103
}
105104

106105
// ReturnStream gives up the read stream by passing it back up through the

lsat/store.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package lsat
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"strings"
@@ -113,7 +112,7 @@ func (f *FileStore) AllTokens() (map[string]*Token, error) {
113112
// just one token, either pending or paid.
114113
// TODO(guggero): Update comment once tokens expire and we keep backups.
115114
tokenDir := filepath.Dir(f.fileName)
116-
files, err := ioutil.ReadDir(tokenDir)
115+
files, err := os.ReadDir(tokenDir)
117116
if err != nil {
118117
return nil, err
119118
}
@@ -156,7 +155,7 @@ func (f *FileStore) StoreToken(newToken *Token) error {
156155
if newToken.isPending() {
157156
newFileName = f.fileNamePending
158157
}
159-
return ioutil.WriteFile(newFileName, bytes, 0600)
158+
return os.WriteFile(newFileName, bytes, 0600)
160159

161160
// Fail on any other error.
162161
case err != nil:
@@ -173,7 +172,7 @@ func (f *FileStore) StoreToken(newToken *Token) error {
173172

174173
// Write the new token first, so we still have the pending
175174
// around if something goes wrong.
176-
err := ioutil.WriteFile(f.fileName, bytes, 0600)
175+
err := os.WriteFile(f.fileName, bytes, 0600)
177176
if err != nil {
178177
return err
179178
}
@@ -206,7 +205,7 @@ func (f *FileStore) RemovePendingToken() error {
206205

207206
// readTokenFile reads a single token from a file and returns it deserialized.
208207
func readTokenFile(tokenFile string) (*Token, error) {
209-
bytes, err := ioutil.ReadFile(tokenFile)
208+
bytes, err := os.ReadFile(tokenFile)
210209
if err != nil {
211210
return nil, err
212211
}

lsat/store_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lsat
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"testing"
@@ -13,7 +12,7 @@ import (
1312
func TestFileStore(t *testing.T) {
1413
t.Parallel()
1514

16-
tempDirName, err := ioutil.TempDir("", "lsatstore")
15+
tempDirName, err := os.MkdirTemp("", "lsatstore")
1716
if err != nil {
1817
t.Fatal(err)
1918
}

proxy/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"crypto/tls"
55
"crypto/x509"
66
"fmt"
7-
"io/ioutil"
87
"net/http"
98
"net/http/httputil"
9+
"os"
1010
"regexp"
1111
"strconv"
1212
"strings"
@@ -329,7 +329,7 @@ func certPool(services []*Service) (*x509.CertPool, error) {
329329
continue
330330
}
331331

332-
b, err := ioutil.ReadFile(service.TLSCertPath)
332+
b, err := os.ReadFile(service.TLSCertPath)
333333
if err != nil {
334334
return nil, err
335335
}

proxy/proxy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"crypto/x509"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"net"
1110
"net/http"
11+
"os"
1212
"path"
1313
"strings"
1414
"testing"
@@ -169,7 +169,7 @@ func runHTTPTest(t *testing.T, tc *testCase) {
169169

170170
// Ensure that we got the response body we expect.
171171
defer closeOrFail(t, resp.Body)
172-
bodyBytes, err := ioutil.ReadAll(resp.Body)
172+
bodyBytes, err := io.ReadAll(resp.Body)
173173
require.NoError(t, err)
174174

175175
require.Equal(t, testHTTPResponseBody, string(bodyBytes))
@@ -188,7 +188,7 @@ func runHTTPTest(t *testing.T, tc *testCase) {
188188

189189
// Ensure that we got the response body we expect.
190190
defer closeOrFail(t, resp.Body)
191-
bodyBytes, err := ioutil.ReadAll(resp.Body)
191+
bodyBytes, err := io.ReadAll(resp.Body)
192192
require.NoError(t, err)
193193

194194
require.Equal(t, testHTTPResponseBody, string(bodyBytes))
@@ -237,7 +237,7 @@ func TestProxyGRPC(t *testing.T) {
237237
func runGRPCTest(t *testing.T, tc *testCase) {
238238
// Since gRPC only really works over TLS, we need to generate a
239239
// certificate and key pair first.
240-
tempDirName, err := ioutil.TempDir("", "proxytest")
240+
tempDirName, err := os.MkdirTemp("", "proxytest")
241241
require.NoError(t, err)
242242
certFile := path.Join(tempDirName, "proxy.cert")
243243
keyFile := path.Join(tempDirName, "proxy.key")

proxy/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"encoding/base64"
55
"encoding/hex"
66
"fmt"
7-
"io/ioutil"
87
"net/http"
8+
"os"
99
"regexp"
1010
"strings"
1111

@@ -154,7 +154,7 @@ func prepareServices(services []*Service) error {
154154
"must be '!file+hex:path'")
155155
}
156156
prefix, fileName := parts[0], parts[1]
157-
bytes, err := ioutil.ReadFile(fileName)
157+
bytes, err := os.ReadFile(fileName)
158158
if err != nil {
159159
return err
160160
}

secrets_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"crypto/sha256"
7-
"io/ioutil"
87
"net/url"
98
"os"
109
"testing"
@@ -22,7 +21,7 @@ import (
2221
func etcdSetup(t *testing.T) (*clientv3.Client, func()) {
2322
t.Helper()
2423

25-
tempDir, err := ioutil.TempDir("", "etcd")
24+
tempDir, err := os.MkdirTemp("", "etcd")
2625
if err != nil {
2726
t.Fatalf("unable to create temp dir: %v", err)
2827
}

0 commit comments

Comments
 (0)