Skip to content

Commit

Permalink
Merge pull request #528 from testwill/ioutil
Browse files Browse the repository at this point in the history
chore: remove refs to deprecated io/ioutil
  • Loading branch information
lucaslorentz authored Sep 2, 2023
2 parents 82f17b9 + ed26fea commit 6fedb34
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
6 changes: 3 additions & 3 deletions caddyfile/fromlabels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package caddyfile

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
Expand All @@ -13,7 +13,7 @@ import (

func TestLabelsToCaddyfile(t *testing.T) {
// load the list of test files from the dir
files, err := ioutil.ReadDir("./testdata/labels")
files, err := os.ReadDir("./testdata/labels")
if err != nil {
t.Errorf("failed to read labels dir: %s", err)
}
Expand All @@ -30,7 +30,7 @@ func TestLabelsToCaddyfile(t *testing.T) {
filename := f.Name()

t.Run(filename, func(t *testing.T) {
data, err := ioutil.ReadFile("./testdata/labels/" + filename)
data, err := os.ReadFile("./testdata/labels/" + filename)
if err != nil {
t.Errorf("failed to read %s dir: %s", filename, err)
}
Expand Down
6 changes: 3 additions & 3 deletions caddyfile/marshal_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package caddyfile

import (
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
Expand All @@ -14,7 +14,7 @@ func TestMarshalUnmarshal(t *testing.T) {
const folder = "./testdata/marshal"

// load the list of test files from the dir
files, err := ioutil.ReadDir(folder)
files, err := os.ReadDir(folder)
if err != nil {
t.Errorf("failed to read process dir: %s", err)
}
Expand All @@ -31,7 +31,7 @@ func TestMarshalUnmarshal(t *testing.T) {
filename := f.Name()

t.Run(filename, func(t *testing.T) {
data, err := ioutil.ReadFile(folder + "/" + filename)
data, err := os.ReadFile(folder + "/" + filename)
if err != nil {
t.Errorf("failed to read %s dir: %s", filename, err)
}
Expand Down
6 changes: 3 additions & 3 deletions caddyfile/merge_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package caddyfile

import (
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
Expand All @@ -14,7 +14,7 @@ func TestMerge(t *testing.T) {
const folder = "./testdata/merge"

// load the list of test files from the dir
files, err := ioutil.ReadDir(folder)
files, err := os.ReadDir(folder)
if err != nil {
t.Errorf("failed to read process dir: %s", err)
}
Expand All @@ -31,7 +31,7 @@ func TestMerge(t *testing.T) {
filename := f.Name()

t.Run(filename, func(t *testing.T) {
data, err := ioutil.ReadFile(folder + "/" + filename)
data, err := os.ReadFile(folder + "/" + filename)
if err != nil {
t.Errorf("failed to read %s dir: %s", filename, err)
}
Expand Down
6 changes: 3 additions & 3 deletions caddyfile/processor_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package caddyfile

import (
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
Expand All @@ -13,7 +13,7 @@ import (

func TestProcessCaddyfile(t *testing.T) {
// load the list of test files from the dir
files, err := ioutil.ReadDir("./testdata/process")
files, err := os.ReadDir("./testdata/process")
if err != nil {
t.Errorf("failed to read process dir: %s", err)
}
Expand All @@ -30,7 +30,7 @@ func TestProcessCaddyfile(t *testing.T) {
filename := f.Name()

t.Run(filename, func(t *testing.T) {
data, err := ioutil.ReadFile("./testdata/process/" + filename)
data, err := os.ReadFile("./testdata/process/" + filename)
if err != nil {
t.Errorf("failed to read %s dir: %s", filename, err)
}
Expand Down
5 changes: 2 additions & 3 deletions docker/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package docker

import (
"io/ioutil"
"os"
"regexp"
"runtime"
Expand Down Expand Up @@ -38,7 +37,7 @@ func (wrapper *dockerUtils) GetCurrentContainerID() (string, error) {
}

func (wrapper *dockerUtils) getCurrentContainerIDFromMountInfo() (string, error) {
bytes, err := ioutil.ReadFile("/proc/self/mountinfo")
bytes, err := os.ReadFile("/proc/self/mountinfo")
if err != nil {
return "", err
}
Expand All @@ -47,7 +46,7 @@ func (wrapper *dockerUtils) getCurrentContainerIDFromMountInfo() (string, error)
}

func (wrapper *dockerUtils) getCurrentContainerIDFromCGroup() (string, error) {
bytes, err := ioutil.ReadFile("/proc/self/cgroup")
bytes, err := os.ReadFile("/proc/self/cgroup")
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net"
"os"
"regexp"
"time"

Expand Down Expand Up @@ -72,7 +72,7 @@ func (g *CaddyfileGenerator) GenerateCaddyfile(logger *zap.Logger) ([]byte, []st

// Add caddyfile from path
if g.options.CaddyfilePath != "" {
dat, err := ioutil.ReadFile(g.options.CaddyfilePath)
dat, err := os.ReadFile(g.options.CaddyfilePath)
if err != nil {
logger.Error("Failed to read Caddyfile", zap.String("path", g.options.CaddyfilePath), zap.Error(err))
} else {
Expand Down
4 changes: 2 additions & 2 deletions generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"io"
"log"
"testing"

Expand All @@ -31,7 +31,7 @@ const swarmIsDisabledLog = `INFO Swarm is available {"new": false}` + newLine
const commonLogs = containerIdLog + ingressNetworksMapLog + swarmIsAvailableLog

func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}

func fmtLabel(s string) string {
Expand Down
6 changes: 3 additions & 3 deletions generator/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package generator

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
Expand All @@ -12,7 +12,7 @@ import (

func TestLabelsToCaddyfile(t *testing.T) {
// load the list of test files from the dir
files, err := ioutil.ReadDir("./testdata/labels")
files, err := os.ReadDir("./testdata/labels")
if err != nil {
t.Errorf("failed to read labels dir: %s", err)
}
Expand All @@ -27,7 +27,7 @@ func TestLabelsToCaddyfile(t *testing.T) {

// read the test file
filename := f.Name()
data, err := ioutil.ReadFile("./testdata/labels/" + filename)
data, err := os.ReadFile("./testdata/labels/" + filename)
if err != nil {
t.Errorf("failed to read %s dir: %s", filename, err)
}
Expand Down
4 changes: 2 additions & 2 deletions loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"path/filepath"
"sync"
Expand Down Expand Up @@ -314,7 +314,7 @@ func (dockerLoader *DockerLoader) updateServer(wg *sync.WaitGroup, server string
return
}

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Error("Failed to read response from", zap.String("server", server), zap.Error(err))
return
Expand Down

0 comments on commit 6fedb34

Please sign in to comment.