Skip to content

Commit 218bdbb

Browse files
committed
Address deprecated ioutil
1 parent 754fe3e commit 218bdbb

File tree

8 files changed

+20
-59
lines changed

8 files changed

+20
-59
lines changed

internal/agent/api/server_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"testing"
1111
"yc-agent/internal/config"
@@ -37,7 +37,7 @@ func TestServer(t *testing.T) {
3737
}
3838

3939
if resp.Body != nil {
40-
all, err := ioutil.ReadAll(resp.Body)
40+
all, err := io.ReadAll(resp.Body)
4141
if err != nil {
4242
t.Fatal(err)
4343
}
@@ -82,7 +82,7 @@ func TestServerCmdActions(t *testing.T) {
8282
}
8383

8484
if resp.Body != nil {
85-
all, err := ioutil.ReadAll(resp.Body)
85+
all, err := io.ReadAll(resp.Body)
8686
if err != nil {
8787
t.Fatal(err)
8888
}
@@ -149,7 +149,7 @@ func TestServerForward(t *testing.T) {
149149
}
150150

151151
if resp.Body != nil {
152-
all, err := ioutil.ReadAll(resp.Body)
152+
all, err := io.ReadAll(resp.Body)
153153
if err != nil {
154154
t.Fatal(err)
155155
}
@@ -199,7 +199,7 @@ func TestAttendanceAPI(t *testing.T) {
199199
}
200200

201201
if resp.Body != nil {
202-
all, err := ioutil.ReadAll(resp.Body)
202+
all, err := io.ReadAll(resp.Body)
203203
if err != nil {
204204
t.Fatal(err)
205205
}

internal/agent/ondemand/ondemand.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"encoding/base64"
88
"errors"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"net/http"
1212
"os"
1313
"os/user"
@@ -988,7 +988,7 @@ func RequestFin(endpoint string) (resp []byte, err error) {
988988
if len(path) > 0 {
989989
pool := x509.NewCertPool()
990990
var ca []byte
991-
ca, err = ioutil.ReadFile(path)
991+
ca, err = os.ReadFile(path)
992992
if err != nil {
993993
return
994994
}
@@ -1008,7 +1008,7 @@ func RequestFin(endpoint string) (resp []byte, err error) {
10081008
post, err := httpClient.Do(req)
10091009
if err == nil {
10101010
defer post.Body.Close()
1011-
resp, err = ioutil.ReadAll(post.Body)
1011+
resp, err = io.ReadAll(post.Body)
10121012
if err == nil {
10131013
logger.Log(
10141014
`yc-fin endpoint: %s

internal/capture/boomi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"os"
99
"strings"
1010
"text/template"
@@ -533,7 +533,7 @@ func makeBoomiRequest(queryToken string, username string, password string, boomi
533533
//fmt.Printf("Request Body: %s\n", string(bodyBytes))
534534

535535
// Reset the request body
536-
req.Body = ioutil.NopCloser(bytes.NewReader(bodyBytes))
536+
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
537537
}
538538

539539
return nil
@@ -646,7 +646,7 @@ func makeAtomConnectorsRequest(queryToken string, username string, password stri
646646
//fmt.Printf("Request Body: %s\n", string(bodyBytes))
647647

648648
// Reset the request body
649-
req.Body = ioutil.NopCloser(bytes.NewReader(bodyBytes))
649+
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
650650
}
651651

652652
return nil

internal/capture/executils/shell.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,6 @@ func (cmd *Command) AddDynamicArg(args ...string) (result Command, err error) {
7474
return
7575
}
7676

77-
func (cmd *Command) addDynamicArg(args ...string) (result Command, err error) {
78-
if cmd == nil {
79-
err = errors.New("invalid nil Command, please use NopCommand instead")
80-
return
81-
}
82-
if *cmd == nil {
83-
return NopCommand, nil
84-
}
85-
n := 0
86-
for _, c := range *cmd {
87-
if c == DynamicArg {
88-
n++
89-
}
90-
}
91-
if n != len(args) {
92-
return *cmd, nil
93-
}
94-
if (*cmd)[0] == WaitCommand {
95-
result = make(Command, 0, len(*cmd)+1)
96-
result = append(result, WaitCommand)
97-
} else {
98-
result = make(Command, 0, len(*cmd))
99-
}
100-
i := 0
101-
for _, c := range *cmd {
102-
switch c {
103-
case WaitCommand:
104-
continue
105-
case DynamicArg:
106-
result = append(result, args[i])
107-
i++
108-
default:
109-
result = append(result, c)
110-
}
111-
}
112-
return
113-
}
114-
11577
var Env []string
11678

11779
func NewCommand(cmd Command, hookers ...Hooker) CmdManager {

internal/capture/gc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package capture
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"os"
88
"path/filepath"
99
"strings"
@@ -30,7 +30,7 @@ func TestProcessLogFile(t *testing.T) {
3030
t.Fatal(err)
3131
}
3232
gc.Seek(0, 0)
33-
all, err := ioutil.ReadAll(gc)
33+
all, err := io.ReadAll(gc)
3434
if err != nil {
3535
t.Fatal(err)
3636
}

internal/capture/post.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"crypto/x509"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net"
109
"net/http"
1110
"os"
@@ -117,7 +116,7 @@ func PostCustomDataWithPositionFuncWithTimeout(endpoint, params string, file *os
117116
path := config.GlobalConfig.CACertPath
118117
if len(path) > 0 {
119118
pool := x509.NewCertPool()
120-
ca, err := ioutil.ReadFile(path)
119+
ca, err := os.ReadFile(path)
121120
if err != nil {
122121
msg = err.Error()
123122
return
@@ -148,7 +147,7 @@ func PostCustomDataWithPositionFuncWithTimeout(endpoint, params string, file *os
148147
}
149148

150149
defer resp.Body.Close()
151-
body, err := ioutil.ReadAll(resp.Body)
150+
body, err := io.ReadAll(resp.Body)
152151
if err != nil {
153152
msg = fmt.Sprintf("PostData get resp err %s", err.Error())
154153
return
@@ -173,7 +172,7 @@ func GetData(endpoint string) (msg string, ok bool) {
173172
path := config.GlobalConfig.CACertPath
174173
if len(path) > 0 {
175174
pool := x509.NewCertPool()
176-
ca, err := ioutil.ReadFile(path)
175+
ca, err := os.ReadFile(path)
177176
if err != nil {
178177
msg = err.Error()
179178
return
@@ -198,7 +197,7 @@ func GetData(endpoint string) (msg string, ok bool) {
198197
}
199198

200199
defer resp.Body.Close()
201-
body, err := ioutil.ReadAll(resp.Body)
200+
body, err := io.ReadAll(resp.Body)
202201
if err != nil {
203202
msg = fmt.Sprintf("GetData get resp err %s", err.Error())
204203
return

internal/capture/post_test.go

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

33
import (
4-
"io/ioutil"
4+
"io"
55
"os"
66
"testing"
77
)
@@ -16,7 +16,7 @@ func TestLastNLines(t *testing.T) {
1616
if err != nil {
1717
t.Fatal(err)
1818
}
19-
bytes, err := ioutil.ReadAll(file)
19+
bytes, err := io.ReadAll(file)
2020
if err != nil {
2121
t.Fatal(err)
2222
}

internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestConfig(t *testing.T) {
125125
if len(GlobalConfig.ProcessTokens) != 2 {
126126
t.Fail()
127127
}
128-
if GlobalConfig.M3Frequency != 5*time.Minute {
128+
if GlobalConfig.M3Frequency != Duration(5*time.Minute) {
129129
t.Fail()
130130
}
131131
})

0 commit comments

Comments
 (0)