Skip to content

Commit 33ccc52

Browse files
authored
chore: remove ioutil (#29)
1 parent 51c41ce commit 33ccc52

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

generate.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package kroki
22

33
import (
4-
"io/ioutil"
54
"os"
65

76
"github.com/pkg/errors"
@@ -24,7 +23,7 @@ func (c *Client) FromString(input string, diagramType DiagramType, imageFormat I
2423

2524
// FromFile takes a file path and returns the image generated by Kroki
2625
func (c *Client) FromFile(path string, diagramType DiagramType, imageFormat ImageFormat) (string, error) {
27-
content, err := ioutil.ReadFile(path)
26+
content, err := os.ReadFile(path)
2827
if err != nil {
2928
return "", errors.Wrapf(err, "fail to read file '%s'", path)
3029
}

generate_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package kroki
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
8+
"os"
89
"strconv"
910
"strings"
1011
"testing"
@@ -141,11 +142,11 @@ func TestFromLargeFile(t *testing.T) {
141142
t.Errorf("FromLargeFile error\nexpectedBody: %s\nactual: %s", expectedRequestMethod, method)
142143
}
143144
uri := strings.Split(r.RequestURI, "/")
144-
body, err := ioutil.ReadAll(r.Body)
145+
body, err := io.ReadAll(r.Body)
145146
if err != nil {
146147
t.Errorf("FromLargeFile unable to read body")
147148
}
148-
content, err := ioutil.ReadFile(file)
149+
content, err := os.ReadFile(file)
149150
if err != nil {
150151
t.Errorf("FromLargeFile unable to read file: %s", file)
151152
}
@@ -178,7 +179,6 @@ func TestFromLargeFile(t *testing.T) {
178179
}
179180
}
180181

181-
182182
func TestWriteToFile(t *testing.T) {
183183
client := New(Configuration{})
184184
expected := "clojure"
@@ -187,7 +187,7 @@ func TestWriteToFile(t *testing.T) {
187187
if err != nil {
188188
t.Errorf("WriteToFile error:\n%+v", err)
189189
}
190-
content, err := ioutil.ReadFile(filePath)
190+
content, err := os.ReadFile(filePath)
191191
if err != nil {
192192
t.Errorf("read file error:\n%+v", err)
193193
}

http.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package kroki
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/url"
99
"path"
@@ -46,7 +46,7 @@ func (c *Client) PostRequestContext(ctx context.Context, payload string, diagram
4646
// read the result
4747
defer response.Body.Close()
4848
if response.StatusCode != http.StatusOK {
49-
body, err := ioutil.ReadAll(response.Body)
49+
body, err := io.ReadAll(response.Body)
5050
var message string
5151
if err != nil {
5252
message = ""
@@ -57,7 +57,7 @@ func (c *Client) PostRequestContext(ctx context.Context, payload string, diagram
5757
"fail to generate the image {status: %d, body: %s}",
5858
response.StatusCode, message)
5959
}
60-
body, err := ioutil.ReadAll(response.Body)
60+
body, err := io.ReadAll(response.Body)
6161
if err != nil {
6262
return "", errors.Wrap(err, "fail to read the response body")
6363
}
@@ -104,7 +104,7 @@ func (c *Client) GetRequestContext(ctx context.Context, payload string, diagramT
104104
// read the result
105105
defer response.Body.Close()
106106
if response.StatusCode != http.StatusOK {
107-
body, err := ioutil.ReadAll(response.Body)
107+
body, err := io.ReadAll(response.Body)
108108
var message string
109109
if err != nil {
110110
message = ""
@@ -115,7 +115,7 @@ func (c *Client) GetRequestContext(ctx context.Context, payload string, diagramT
115115
"fail to generate the image {status: %d, body: %s}",
116116
response.StatusCode, message)
117117
}
118-
body, err := ioutil.ReadAll(response.Body)
118+
body, err := io.ReadAll(response.Body)
119119
if err != nil {
120120
return "", errors.Wrap(err, "fail to read the response body")
121121
}

0 commit comments

Comments
 (0)