Skip to content

Commit bca67fd

Browse files
authored
Stop using deprecated package 'ioutil' (#174)
1 parent cac94e6 commit bca67fd

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

internal/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package killgrave
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"os"
88
"path"
99

@@ -146,7 +146,7 @@ func NewConfigFromFile(cfgPath string) (Config, error) {
146146
defer configFile.Close()
147147

148148
var cfg Config
149-
bytes, _ := ioutil.ReadAll(configFile)
149+
bytes, _ := io.ReadAll(configFile)
150150
if err := yaml.Unmarshal(bytes, &cfg); err != nil {
151151
return Config{}, fmt.Errorf("%w: error while unmarshalling configFile file %s, using default configuration instead", err, cfgPath)
152152
}

internal/server/http/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package http
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"log"
66
"net/http"
77
"os"
@@ -49,7 +49,7 @@ func fetchBodyFromFile(bodyFile string) (bytes []byte) {
4949

5050
f, _ := os.Open(bodyFile)
5151
defer f.Close()
52-
bytes, err := ioutil.ReadAll(f)
52+
bytes, err := io.ReadAll(f)
5353
if err != nil {
5454
log.Printf("imposible read the file %s: %v\n", bodyFile, err)
5555
}

internal/server/http/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package http
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88
"os"
@@ -40,7 +40,7 @@ func TestImposterHandler(t *testing.T) {
4040

4141
f, _ := os.Open(bodyFile)
4242
defer f.Close()
43-
expectedBodyFileData, _ := ioutil.ReadAll(f)
43+
expectedBodyFileData, _ := io.ReadAll(f)
4444

4545
var dataTest = []struct {
4646
name string

internal/server/http/route_matchers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"log"
99
"net/http"
1010
"os"
@@ -37,15 +37,15 @@ func validateSchema(imposter Imposter, req *http.Request) error {
3737

3838
defer func() {
3939
req.Body.Close()
40-
req.Body = ioutil.NopCloser(bytes.NewBuffer(requestBodyBytes))
40+
req.Body = io.NopCloser(bytes.NewBuffer(requestBodyBytes))
4141
}()
4242

4343
schemaFile := imposter.CalculateFilePath(*imposter.Request.SchemaFile)
4444
if _, err := os.Stat(schemaFile); os.IsNotExist(err) {
4545
return fmt.Errorf("%w: the schema file %s not found", err, schemaFile)
4646
}
4747

48-
requestBodyBytes, err := ioutil.ReadAll(req.Body)
48+
requestBodyBytes, err := io.ReadAll(req.Body)
4949
if err != nil {
5050
return fmt.Errorf("%w: impossible read the request body", err)
5151
}
@@ -60,7 +60,7 @@ func validateSchema(imposter Imposter, req *http.Request) error {
6060
return fmt.Errorf("%w: impossible find the schema", err)
6161
}
6262

63-
schemaBytes, err := ioutil.ReadFile(schemaFilePath)
63+
schemaBytes, err := os.ReadFile(schemaFilePath)
6464
if err != nil {
6565
return fmt.Errorf("%w: impossible read the schema", err)
6666
}

internal/server/http/route_matchers_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package http
33
import (
44
"bytes"
55
"errors"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"testing"
99

@@ -12,10 +12,10 @@ import (
1212
)
1313

1414
func TestMatcherBySchema(t *testing.T) {
15-
bodyA := ioutil.NopCloser(bytes.NewReader([]byte("{\"type\": \"gopher\"}")))
16-
bodyB := ioutil.NopCloser(bytes.NewReader([]byte("{\"type\": \"cat\"}")))
17-
emptyBody := ioutil.NopCloser(bytes.NewReader([]byte("")))
18-
wrongBody := ioutil.NopCloser(errReader(0))
15+
bodyA := io.NopCloser(bytes.NewReader([]byte("{\"type\": \"gopher\"}")))
16+
bodyB := io.NopCloser(bytes.NewReader([]byte("{\"type\": \"cat\"}")))
17+
emptyBody := io.NopCloser(bytes.NewReader([]byte("")))
18+
wrongBody := io.NopCloser(errReader(0))
1919

2020
schemaGopherFile := "test/testdata/imposters/schemas/type_gopher.json"
2121
schemaCatFile := "test/testdata/imposters/schemas/type_cat.json"

internal/watcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package killgrave
22

33
import (
44
"errors"
5-
"io/ioutil"
5+
"io"
66
"log"
77
"os"
88
"testing"
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func TestMain(m *testing.M) {
16-
log.SetOutput(ioutil.Discard)
16+
log.SetOutput(io.Discard)
1717
os.Exit(m.Run())
1818
}
1919

0 commit comments

Comments
 (0)