From 8aa8c7624ed63cfbdd575c3ceab3b6b96d7d6237 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Sun, 14 Jan 2024 19:50:09 +0900 Subject: [PATCH] replace deprecated io/ioutil package Signed-off-by: nnnkkk7 --- pkg/clients/docker/docker_client.go | 18 +++++++++--------- pkg/platform/telemetry/utils.go | 3 +-- .../integrations/httpparser/httpparser.go | 3 +-- pkg/proxy/proxy.go | 3 +-- utils/utils.go | 4 ++-- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pkg/clients/docker/docker_client.go b/pkg/clients/docker/docker_client.go index d3c3eacb3..feb32b364 100755 --- a/pkg/clients/docker/docker_client.go +++ b/pkg/clients/docker/docker_client.go @@ -3,7 +3,7 @@ package docker import ( "context" "fmt" - "io/ioutil" + "os" "path/filepath" "time" @@ -216,7 +216,7 @@ type Compose struct { // CheckBindMounts returns information about whether bind mounts if they are being used contain relative file names or not func (idc *internalDockerClient) CheckBindMounts(filePath string) bool { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { idc.logger.Error("error reading file", zap.Any("filePath", filePath), zap.Error(err)) return false @@ -261,7 +261,7 @@ func (idc *internalDockerClient) CheckBindMounts(filePath string) bool { // CheckNetworkInfo returns information about network name and also about whether the network is external or not in a docker-compose file. func (idc *internalDockerClient) CheckNetworkInfo(filePath string) (bool, bool, string) { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { idc.logger.Error("error reading file", zap.Any("filePath", filePath), zap.Error(err)) return false, false, "" @@ -366,7 +366,7 @@ func (idc *internalDockerClient) GetHostWorkingDirectory() (string, error) { // ReplaceRelativePaths replaces relative paths in bind mounts with absolute paths func (idc *internalDockerClient) ReplaceRelativePaths(dockerComposefilePath, newComposeFile string) error { - data, err := ioutil.ReadFile(dockerComposefilePath) + data, err := os.ReadFile(dockerComposefilePath) if err != nil { return err } @@ -426,7 +426,7 @@ func (idc *internalDockerClient) ReplaceRelativePaths(dockerComposefilePath, new } newFilePath := filepath.Join(filepath.Dir(dockerComposefilePath), newComposeFile) - err = ioutil.WriteFile(newFilePath, newData, 0644) + err = os.WriteFile(newFilePath, newData, 0644) if err != nil { return err } @@ -436,7 +436,7 @@ func (idc *internalDockerClient) ReplaceRelativePaths(dockerComposefilePath, new // MakeNetworkExternal makes the existing network of the user docker compose file external and save it to a new file func (idc *internalDockerClient) MakeNetworkExternal(dockerComposefilePath, newComposeFile string) error { - data, err := ioutil.ReadFile(dockerComposefilePath) + data, err := os.ReadFile(dockerComposefilePath) if err != nil { return err } @@ -493,7 +493,7 @@ func (idc *internalDockerClient) MakeNetworkExternal(dockerComposefilePath, newC } newFilePath := filepath.Join(filepath.Dir(dockerComposefilePath), newComposeFile) - err = ioutil.WriteFile(newFilePath, newData, 0644) + err = os.WriteFile(newFilePath, newData, 0644) if err != nil { return err } @@ -504,7 +504,7 @@ func (idc *internalDockerClient) MakeNetworkExternal(dockerComposefilePath, newC // AddNetworkToCompose adds the keploy-network network to the new docker compose file and copy rest of the contents from // existing user docker compose file func (idc *internalDockerClient) AddNetworkToCompose(dockerComposefilePath, newComposeFile string) error { - data, err := ioutil.ReadFile(dockerComposefilePath) + data, err := os.ReadFile(dockerComposefilePath) if err != nil { return err } @@ -579,7 +579,7 @@ func (idc *internalDockerClient) AddNetworkToCompose(dockerComposefilePath, newC } newFilePath := filepath.Join(filepath.Dir(dockerComposefilePath), newComposeFile) - err = ioutil.WriteFile(newFilePath, newData, 0644) + err = os.WriteFile(newFilePath, newData, 0644) if err != nil { return err } diff --git a/pkg/platform/telemetry/utils.go b/pkg/platform/telemetry/utils.go index f94592eee..a1022fdbe 100644 --- a/pkg/platform/telemetry/utils.go +++ b/pkg/platform/telemetry/utils.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "net/http" "go.keploy.io/server/pkg/models" @@ -31,7 +30,7 @@ func unmarshalResp(resp *http.Response, log *zap.Logger) (id string, err error) }(resp.Body) var res map[string]string - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { log.Debug("failed to read response from telemetry server", zap.String("url", "https://telemetry.keploy.io/analytics"), zap.Error(err)) return diff --git a/pkg/proxy/integrations/httpparser/httpparser.go b/pkg/proxy/integrations/httpparser/httpparser.go index acc53e31c..e640c8311 100755 --- a/pkg/proxy/integrations/httpparser/httpparser.go +++ b/pkg/proxy/integrations/httpparser/httpparser.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -470,7 +469,7 @@ func decodeOutgoingHttp(requestBuffer []byte, clientConn, destConn net.Conn, h * return } - reqBody, err := ioutil.ReadAll(req.Body) + reqBody, err := io.ReadAll(req.Body) if err != nil { logger.Error("failed to read from request body", zap.Any("metadata", getReqMeta(req)), zap.Error(err)) return diff --git a/pkg/proxy/proxy.go b/pkg/proxy/proxy.go index 90ae2408f..1313f8c89 100755 --- a/pkg/proxy/proxy.go +++ b/pkg/proxy/proxy.go @@ -10,7 +10,6 @@ import ( "embed" "fmt" "io" - "io/ioutil" "log" "net" "os" @@ -158,7 +157,7 @@ func isJavaInstalled() bool { // to extract ca certificate to temp func ExtractCertToTemp() (string, error) { - tempFile, err := ioutil.TempFile("", "ca.crt") + tempFile, err := os.CreateTemp("", "ca.crt") if err != nil { return "", err } diff --git a/utils/utils.go b/utils/utils.go index ab2ecbef7..e9fdf717e 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net" "net/http" "os" @@ -118,7 +118,7 @@ func attachLogFileToSentry(logFilePath string) { } defer file.Close() - content, _ := ioutil.ReadAll(file) + content, _ := io.ReadAll(file) sentry.ConfigureScope(func(scope *sentry.Scope) { scope.SetExtra("logfile", string(content))