Skip to content

Commit

Permalink
replace deprecated io/ioutil package
Browse files Browse the repository at this point in the history
Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
  • Loading branch information
nnnkkk7 committed Jan 14, 2024
1 parent be573eb commit def8dc0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
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 @@ -215,7 +215,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 @@ -260,7 +260,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 @@ -359,7 +359,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 @@ -419,7 +419,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 @@ -429,7 +429,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 @@ -486,7 +486,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 @@ -497,7 +497,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 @@ -572,7 +572,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 @@ -344,7 +343,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.Error(err))

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 @@ -153,7 +152,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 @@ -4,7 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"runtime/debug"
"strings"
Expand Down Expand Up @@ -58,7 +58,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

0 comments on commit def8dc0

Please sign in to comment.