mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-24 03:46:24 +00:00
refactor: remove ioutil module usage
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
291c4f6361
commit
82d04d63b6
@ -4,7 +4,6 @@ package file
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@ -27,7 +26,7 @@ type file struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *file) Read() ([]byte, error) {
|
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
|
// Watch listen for config changes and send updated content to the updates channel
|
||||||
|
@ -4,7 +4,6 @@ package file
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@ -20,7 +19,7 @@ import (
|
|||||||
|
|
||||||
func newConfigFile(t *testing.T) (config.Config, string, func()) {
|
func newConfigFile(t *testing.T) (config.Config, string, func()) {
|
||||||
path := filepath.Join(os.TempDir(), "config.yaml")
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
cleanUp := func() {
|
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()) {
|
func newSymlinkedConfigFile(t *testing.T) (config.Config, string, string, func()) {
|
||||||
watchDir, err := ioutil.TempDir("", "")
|
watchDir, err := os.MkdirTemp("", "")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
dataDir1 := path.Join(watchDir, "data1")
|
dataDir1 := path.Join(watchDir, "data1")
|
||||||
err = os.Mkdir(dataDir1, 0o777)
|
err = os.Mkdir(dataDir1, 0o777)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
realConfigFile := path.Join(dataDir1, "config.yaml")
|
realConfigFile := path.Join(dataDir1, "config.yaml")
|
||||||
t.Logf("Real config file location: %s\n", realConfigFile)
|
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)
|
require.Nil(t, err)
|
||||||
cleanup := func() {
|
cleanup := func() {
|
||||||
os.RemoveAll(watchDir)
|
os.RemoveAll(watchDir)
|
||||||
@ -64,7 +63,7 @@ func TestWatch(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// when overwriting the file and waiting for the custom change notification handler to be triggered
|
// 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
|
b := <-updates
|
||||||
// then the config value should have changed
|
// then the config value should have changed
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -87,7 +86,7 @@ func TestWatch(t *testing.T) {
|
|||||||
err := os.MkdirAll(dataDir2, 0o777)
|
err := os.MkdirAll(dataDir2, 0o777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
configFile2 := path.Join(dataDir2, "config.yaml")
|
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)
|
require.NoError(t, err)
|
||||||
// change the symlink using the `ln -sfn` command
|
// change the symlink using the `ln -sfn` command
|
||||||
err = exec.Command("ln", "-sfn", dataDir2, path.Join(watchDir, "data")).Run()
|
err = exec.Command("ln", "-sfn", dataDir2, path.Join(watchDir, "data")).Run()
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -267,7 +266,7 @@ func run(opts ...service.Option) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -122,7 +122,7 @@ func decode(record []string) (*mdnsTxt, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rbuf, err := ioutil.ReadAll(zr)
|
rbuf, err := io.ReadAll(zr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
@ -533,7 +533,7 @@ func (o *options) parseTLSConfig() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
caCert, err := ioutil.ReadFile(o.caCert)
|
caCert, err := os.ReadFile(o.caCert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user