mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-17 17:14:19 +01:00
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.
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -414,7 +413,7 @@ func getConfig() (*Config, error) {
|
|||||||
|
|
||||||
// Read our config file, either from the custom path provided or our
|
// Read our config file, either from the custom path provided or our
|
||||||
// default location.
|
// default location.
|
||||||
b, err := ioutil.ReadFile(configFile)
|
b, err := os.ReadFile(configFile)
|
||||||
switch {
|
switch {
|
||||||
// If the file was found, unmarshal it.
|
// If the file was found, unmarshal it.
|
||||||
case err == nil:
|
case err == nil:
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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
|
// reader, then read all the encoded bytes until the EOF is emitted by
|
||||||
// the reader.
|
// the reader.
|
||||||
msgReader := io.LimitReader(reader, int64(msgLen))
|
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
|
// ReturnStream gives up the read stream by passing it back up through the
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package lsat
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -113,7 +112,7 @@ func (f *FileStore) AllTokens() (map[string]*Token, error) {
|
|||||||
// just one token, either pending or paid.
|
// just one token, either pending or paid.
|
||||||
// TODO(guggero): Update comment once tokens expire and we keep backups.
|
// TODO(guggero): Update comment once tokens expire and we keep backups.
|
||||||
tokenDir := filepath.Dir(f.fileName)
|
tokenDir := filepath.Dir(f.fileName)
|
||||||
files, err := ioutil.ReadDir(tokenDir)
|
files, err := os.ReadDir(tokenDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -156,7 +155,7 @@ func (f *FileStore) StoreToken(newToken *Token) error {
|
|||||||
if newToken.isPending() {
|
if newToken.isPending() {
|
||||||
newFileName = f.fileNamePending
|
newFileName = f.fileNamePending
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(newFileName, bytes, 0600)
|
return os.WriteFile(newFileName, bytes, 0600)
|
||||||
|
|
||||||
// Fail on any other error.
|
// Fail on any other error.
|
||||||
case err != nil:
|
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
|
// Write the new token first, so we still have the pending
|
||||||
// around if something goes wrong.
|
// around if something goes wrong.
|
||||||
err := ioutil.WriteFile(f.fileName, bytes, 0600)
|
err := os.WriteFile(f.fileName, bytes, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -206,7 +205,7 @@ func (f *FileStore) RemovePendingToken() error {
|
|||||||
|
|
||||||
// readTokenFile reads a single token from a file and returns it deserialized.
|
// readTokenFile reads a single token from a file and returns it deserialized.
|
||||||
func readTokenFile(tokenFile string) (*Token, error) {
|
func readTokenFile(tokenFile string) (*Token, error) {
|
||||||
bytes, err := ioutil.ReadFile(tokenFile)
|
bytes, err := os.ReadFile(tokenFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package lsat
|
package lsat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -13,7 +12,7 @@ import (
|
|||||||
func TestFileStore(t *testing.T) {
|
func TestFileStore(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
tempDirName, err := ioutil.TempDir("", "lsatstore")
|
tempDirName, err := os.MkdirTemp("", "lsatstore")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -329,7 +329,7 @@ func certPool(services []*Service) (*x509.CertPool, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := ioutil.ReadFile(service.TLSCertPath)
|
b, err := os.ReadFile(service.TLSCertPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -169,7 +169,7 @@ func runHTTPTest(t *testing.T, tc *testCase) {
|
|||||||
|
|
||||||
// Ensure that we got the response body we expect.
|
// Ensure that we got the response body we expect.
|
||||||
defer closeOrFail(t, resp.Body)
|
defer closeOrFail(t, resp.Body)
|
||||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
bodyBytes, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, testHTTPResponseBody, string(bodyBytes))
|
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.
|
// Ensure that we got the response body we expect.
|
||||||
defer closeOrFail(t, resp.Body)
|
defer closeOrFail(t, resp.Body)
|
||||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
bodyBytes, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, testHTTPResponseBody, string(bodyBytes))
|
require.Equal(t, testHTTPResponseBody, string(bodyBytes))
|
||||||
@@ -237,7 +237,7 @@ func TestProxyGRPC(t *testing.T) {
|
|||||||
func runGRPCTest(t *testing.T, tc *testCase) {
|
func runGRPCTest(t *testing.T, tc *testCase) {
|
||||||
// Since gRPC only really works over TLS, we need to generate a
|
// Since gRPC only really works over TLS, we need to generate a
|
||||||
// certificate and key pair first.
|
// certificate and key pair first.
|
||||||
tempDirName, err := ioutil.TempDir("", "proxytest")
|
tempDirName, err := os.MkdirTemp("", "proxytest")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
certFile := path.Join(tempDirName, "proxy.cert")
|
certFile := path.Join(tempDirName, "proxy.cert")
|
||||||
keyFile := path.Join(tempDirName, "proxy.key")
|
keyFile := path.Join(tempDirName, "proxy.key")
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ func prepareServices(services []*Service) error {
|
|||||||
"must be '!file+hex:path'")
|
"must be '!file+hex:path'")
|
||||||
}
|
}
|
||||||
prefix, fileName := parts[0], parts[1]
|
prefix, fileName := parts[0], parts[1]
|
||||||
bytes, err := ioutil.ReadFile(fileName)
|
bytes, err := os.ReadFile(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -22,7 +21,7 @@ import (
|
|||||||
func etcdSetup(t *testing.T) (*clientv3.Client, func()) {
|
func etcdSetup(t *testing.T) (*clientv3.Client, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
tempDir, err := ioutil.TempDir("", "etcd")
|
tempDir, err := os.MkdirTemp("", "etcd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create temp dir: %v", err)
|
t.Fatalf("unable to create temp dir: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user