Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace deprecated io/ioutil package #1350

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions pkg/clients/docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package docker
import (
"context"
"fmt"
"io/ioutil"

"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, ""
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/platform/telemetry/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"

"go.keploy.io/server/pkg/models"
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/proxy/integrations/httpparser/httpparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"embed"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -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))
Expand Down