Skip to content

Commit

Permalink
chore: remove ioutil (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
arukiidou authored Mar 22, 2024
1 parent 51c41ce commit 33ccc52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
3 changes: 1 addition & 2 deletions generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kroki

import (
"io/ioutil"
"os"

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

// FromFile takes a file path and returns the image generated by Kroki
func (c *Client) FromFile(path string, diagramType DiagramType, imageFormat ImageFormat) (string, error) {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return "", errors.Wrapf(err, "fail to read file '%s'", path)
}
Expand Down
10 changes: 5 additions & 5 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package kroki

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -141,11 +142,11 @@ func TestFromLargeFile(t *testing.T) {
t.Errorf("FromLargeFile error\nexpectedBody: %s\nactual: %s", expectedRequestMethod, method)
}
uri := strings.Split(r.RequestURI, "/")
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("FromLargeFile unable to read body")
}
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
t.Errorf("FromLargeFile unable to read file: %s", file)
}
Expand Down Expand Up @@ -178,7 +179,6 @@ func TestFromLargeFile(t *testing.T) {
}
}


func TestWriteToFile(t *testing.T) {
client := New(Configuration{})
expected := "clojure"
Expand All @@ -187,7 +187,7 @@ func TestWriteToFile(t *testing.T) {
if err != nil {
t.Errorf("WriteToFile error:\n%+v", err)
}
content, err := ioutil.ReadFile(filePath)
content, err := os.ReadFile(filePath)
if err != nil {
t.Errorf("read file error:\n%+v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kroki
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -46,7 +46,7 @@ func (c *Client) PostRequestContext(ctx context.Context, payload string, diagram
// read the result
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
var message string
if err != nil {
message = ""
Expand All @@ -57,7 +57,7 @@ func (c *Client) PostRequestContext(ctx context.Context, payload string, diagram
"fail to generate the image {status: %d, body: %s}",
response.StatusCode, message)
}
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return "", errors.Wrap(err, "fail to read the response body")
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func (c *Client) GetRequestContext(ctx context.Context, payload string, diagramT
// read the result
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
var message string
if err != nil {
message = ""
Expand All @@ -115,7 +115,7 @@ func (c *Client) GetRequestContext(ctx context.Context, payload string, diagramT
"fail to generate the image {status: %d, body: %s}",
response.StatusCode, message)
}
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return "", errors.Wrap(err, "fail to read the response body")
}
Expand Down

0 comments on commit 33ccc52

Please sign in to comment.