Skip to content

Commit 6baa5f1

Browse files
committed
chore: remove refs to deprecated io/ioutil
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
1 parent 7272ef7 commit 6baa5f1

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

antlr/GruleParserV3_test.go

+3-3
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

+2-2
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

+3-3
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

+3-3
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

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"fmt"
2020
"gopkg.in/src-d/go-billy.v4"
2121
"io"
22-
"io/ioutil"
2322
"net/http"
23+
"os"
2424
"path/filepath"
2525
"time"
2626

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

61-
return ioutil.ReadAll(res.Reader)
61+
return io.ReadAll(res.Reader)
6262
}
6363

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

126-
finfos, err := ioutil.ReadDir(path)
126+
finfos, err := os.ReadDir(path)
127127

128128
if err != nil {
129129

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

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

187187
return nil, err
@@ -279,7 +279,7 @@ func (res *URLResource) Load() ([]byte, error) {
279279
return nil, err
280280
}
281281
defer resp.Body.Close()
282-
data, err := ioutil.ReadAll(resp.Body)
282+
data, err := io.ReadAll(resp.Body)
283283
if err != nil {
284284

285285
return nil, err
@@ -359,7 +359,7 @@ func (bundle *GITResourceBundle) loadPath(url, path string, fileSyst billy.Files
359359

360360
return nil, err
361361
}
362-
bytes, err := ioutil.ReadAll(f)
362+
bytes, err := io.ReadAll(f)
363363
if err != nil {
364364

365365
return nil, err

0 commit comments

Comments
 (0)