refactor: remove ioutil module usage

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2023-03-11 12:27:30 +01:00
parent 291c4f6361
commit 82d04d63b6
Signed by: adphi
GPG Key ID: 46BE4062DB2397FF
5 changed files with 11 additions and 14 deletions

View File

@ -4,7 +4,6 @@ package file
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -27,7 +26,7 @@ type file struct {
}
func (c *file) Read() ([]byte, error) {
return ioutil.ReadFile(c.path)
return os.ReadFile(c.path)
}
// Watch listen for config changes and send updated content to the updates channel

View File

@ -4,7 +4,6 @@ package file
import (
"context"
"io/ioutil"
"os"
"os/exec"
"path"
@ -20,7 +19,7 @@ import (
func newConfigFile(t *testing.T) (config.Config, string, func()) {
path := filepath.Join(os.TempDir(), "config.yaml")
if err := ioutil.WriteFile(path, []byte("ok"), os.ModePerm); err != nil {
if err := os.WriteFile(path, []byte("ok"), os.ModePerm); err != nil {
t.Fatal(err)
}
cleanUp := func() {
@ -32,14 +31,14 @@ func newConfigFile(t *testing.T) (config.Config, string, func()) {
}
func newSymlinkedConfigFile(t *testing.T) (config.Config, string, string, func()) {
watchDir, err := ioutil.TempDir("", "")
watchDir, err := os.MkdirTemp("", "")
require.Nil(t, err)
dataDir1 := path.Join(watchDir, "data1")
err = os.Mkdir(dataDir1, 0o777)
require.Nil(t, err)
realConfigFile := path.Join(dataDir1, "config.yaml")
t.Logf("Real config file location: %s\n", realConfigFile)
err = ioutil.WriteFile(realConfigFile, []byte("foo: bar\n"), 0o640)
err = os.WriteFile(realConfigFile, []byte("foo: bar\n"), 0o640)
require.Nil(t, err)
cleanup := func() {
os.RemoveAll(watchDir)
@ -64,7 +63,7 @@ func TestWatch(t *testing.T) {
t.Fatal(err)
}
// when overwriting the file and waiting for the custom change notification handler to be triggered
err := ioutil.WriteFile(cpath, []byte("foo: baz\n"), 0o640)
err := os.WriteFile(cpath, []byte("foo: baz\n"), 0o640)
b := <-updates
// then the config value should have changed
require.Nil(t, err)
@ -87,7 +86,7 @@ func TestWatch(t *testing.T) {
err := os.MkdirAll(dataDir2, 0o777)
require.NoError(t, err)
configFile2 := path.Join(dataDir2, "config.yaml")
err = ioutil.WriteFile(configFile2, []byte("foo: baz\n"), 0o640)
err = os.WriteFile(configFile2, []byte("foo: baz\n"), 0o640)
require.NoError(t, err)
// change the symlink using the `ln -sfn` command
err = exec.Command("ln", "-sfn", dataDir2, path.Join(watchDir, "data")).Run()

View File

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"time"
@ -267,7 +266,7 @@ func run(opts ...service.Option) {
log.Fatal(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

View File

@ -7,7 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"strconv"
"strings"
@ -122,7 +122,7 @@ func decode(record []string) (*mdnsTxt, error) {
return nil, err
}
rbuf, err := ioutil.ReadAll(zr)
rbuf, err := io.ReadAll(zr)
if err != nil {
return nil, err
}

View File

@ -6,8 +6,8 @@ import (
"crypto/x509"
"embed"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
@ -533,7 +533,7 @@ func (o *options) parseTLSConfig() error {
}
return nil
}
caCert, err := ioutil.ReadFile(o.caCert)
caCert, err := os.ReadFile(o.caCert)
if err != nil {
return err
}