Skip to content

Commit 7d42e87

Browse files
committed
chore: remove refs to deprecated io/ioutil
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
1 parent e4e90fe commit 7d42e87

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

antlr/GruleParserV3_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package antlr
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
19+
"os"
2020
"reflect"
2121
"testing"
2222

@@ -105,7 +105,7 @@ type GrandChild struct {
105105
}
106106

107107
func TestV3Lexer(t *testing.T) {
108-
data, err := ioutil.ReadFile("./sample4.grl")
108+
data, err := os.ReadFile("./sample4.grl")
109109
if err != nil {
110110
t.Fatal(err)
111111
} else {
@@ -129,7 +129,7 @@ func TestV3Lexer(t *testing.T) {
129129

130130
func TestV3Parser(t *testing.T) {
131131
// logrus.SetLevel(logrus.TraceLevel)
132-
data, err := ioutil.ReadFile("./sample4.grl")
132+
data, err := os.ReadFile("./sample4.grl")
133133
if err != nil {
134134
t.Fatal(err)
135135
} else {

editor/EvaluationRoute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/hyperjumptech/grule-rule-engine/engine"
1010
"github.com/hyperjumptech/grule-rule-engine/pkg"
1111
mux "github.com/hyperjumptech/hyper-mux"
12-
"io/ioutil"
12+
"io"
1313
"net/http"
1414
)
1515

@@ -25,7 +25,7 @@ type EvaluateRequest struct {
2525

2626
func InitializeEvaluationRoute(router *mux.HyperMux) {
2727
router.AddRoute("/evaluate", http.MethodPost, func(writer http.ResponseWriter, reader *http.Request) {
28-
bodyBytes, err := ioutil.ReadAll(reader.Body)
28+
bodyBytes, err := io.ReadAll(reader.Body)
2929
if err != nil {
3030
writer.WriteHeader(http.StatusInternalServerError)
3131
_, _ = writer.Write([]byte(fmt.Sprintf("error while reading body stream. got %v", err)))

examples/benchmark/ExecRules_benchmark_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/hyperjumptech/grule-rule-engine/builder"
2121
"github.com/hyperjumptech/grule-rule-engine/engine"
2222
"github.com/hyperjumptech/grule-rule-engine/pkg"
23-
"io/ioutil"
23+
"os"
2424
"testing"
2525
)
2626

@@ -66,7 +66,7 @@ func Benchmark_Grule_Execution_Engine(b *testing.B) {
6666
}
6767

6868
func load100RulesIntoKnowledgebase() {
69-
input, _ := ioutil.ReadFile("100_rules.grl")
69+
input, _ := os.ReadFile("100_rules.grl")
7070
rules := string(input)
7171
fact := &RideFact{
7272
Distance: 6000,
@@ -83,7 +83,7 @@ func load100RulesIntoKnowledgebase() {
8383
}
8484

8585
func load1000RulesIntoKnowledgebase() {
86-
input, _ := ioutil.ReadFile("1000_rules.grl")
86+
input, _ := os.ReadFile("1000_rules.grl")
8787
rules := string(input)
8888
fact := &RideFact{
8989
Distance: 6000,

examples/benchmark/LoadRules_benchmark_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/hyperjumptech/grule-rule-engine/ast"
2020
"github.com/hyperjumptech/grule-rule-engine/builder"
2121
"github.com/hyperjumptech/grule-rule-engine/pkg"
22-
"io/ioutil"
22+
"os"
2323
"testing"
2424
)
2525

@@ -58,7 +58,7 @@ func Benchmark_Grule_Load_Rules(b *testing.B) {
5858
}
5959

6060
func load100RulesIntoKnowledgeBase() {
61-
input, _ := ioutil.ReadFile("100_rules.grl")
61+
input, _ := os.ReadFile("100_rules.grl")
6262
rules := string(input)
6363
fact := &RideFact{
6464
Distance: 6000,
@@ -74,7 +74,7 @@ func load100RulesIntoKnowledgeBase() {
7474
}
7575

7676
func load1000RulesIntoKnowledgeBase() {
77-
input, _ := ioutil.ReadFile("1000_rules.grl")
77+
input, _ := os.ReadFile("1000_rules.grl")
7878
rules := string(input)
7979
fact := &RideFact{
8080
Distance: 6000,

pkg/resource.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"context"
1919
"fmt"
2020
"io"
21-
"io/ioutil"
2221
"net/http"
22+
"os"
2323
"path/filepath"
2424
"time"
2525

@@ -59,7 +59,7 @@ type ReaderResource struct {
5959
// Load will load the resource into byte array.
6060
func (res *ReaderResource) Load() ([]byte, error) {
6161

62-
return ioutil.ReadAll(res.Reader)
62+
return io.ReadAll(res.Reader)
6363
}
6464

6565
// String will state the resource source.
@@ -124,7 +124,7 @@ func (bundle *FileResourceBundle) MustLoad() []Resource {
124124
func (bundle *FileResourceBundle) loadPath(path string) ([]Resource, error) {
125125
logger.Log.Tracef("Enter directory %s", path)
126126

127-
finfos, err := ioutil.ReadDir(path)
127+
finfos, err := os.ReadDir(path)
128128

129129
if err != nil {
130130

@@ -148,7 +148,7 @@ func (bundle *FileResourceBundle) loadPath(path string) ([]Resource, error) {
148148
}
149149
if matched {
150150
logger.Log.Debugf("Loading file %s", fulPath)
151-
bytes, err := ioutil.ReadFile(fulPath)
151+
bytes, err := os.ReadFile(fulPath)
152152
if err != nil {
153153
return nil, err
154154
}
@@ -182,7 +182,7 @@ func (res *FileResource) Load() ([]byte, error) {
182182

183183
return res.Bytes, nil
184184
}
185-
data, err := ioutil.ReadFile(res.Path)
185+
data, err := os.ReadFile(res.Path)
186186
if err != nil {
187187

188188
return nil, err
@@ -280,7 +280,7 @@ func (res *URLResource) Load() ([]byte, error) {
280280
return nil, err
281281
}
282282
defer resp.Body.Close()
283-
data, err := ioutil.ReadAll(resp.Body)
283+
data, err := io.ReadAll(resp.Body)
284284
if err != nil {
285285

286286
return nil, err
@@ -360,7 +360,7 @@ func (bundle *GITResourceBundle) loadPath(url, path string, fileSyst billy.Files
360360

361361
return nil, err
362362
}
363-
bytes, err := ioutil.ReadAll(f)
363+
bytes, err := io.ReadAll(f)
364364
if err != nil {
365365

366366
return nil, err

0 commit comments

Comments
 (0)