chore: remove refs to deprecated io/ioutil

This commit is contained in:
guoguangwu
2023-06-21 12:12:27 +08:00
parent 339e243472
commit 6dc23ca804
15 changed files with 36 additions and 43 deletions
@@ -18,7 +18,7 @@ package custompluginmonitor
import (
"encoding/json"
"io/ioutil"
"os"
"time"
"github.com/golang/glog"
@@ -57,7 +57,7 @@ func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
configPath: configPath,
tomb: tomb.NewTomb(),
}
f, err := ioutil.ReadFile(configPath)
f, err := os.ReadFile(configPath)
if err != nil {
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
}
+2 -3
View File
@@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os/exec"
"strings"
"sync"
@@ -132,12 +131,12 @@ func (p *Plugin) runRules() {
// readFromReader reads the maxBytes from the reader and drains the rest.
func readFromReader(reader io.ReadCloser, maxBytes int64) ([]byte, error) {
limitReader := io.LimitReader(reader, maxBytes)
data, err := ioutil.ReadAll(limitReader)
data, err := io.ReadAll(limitReader)
if err != nil {
return []byte{}, err
}
// Drain the reader
if _, err := io.Copy(ioutil.Discard, reader); err != nil {
if _, err := io.Copy(io.Discard, reader); err != nil {
return []byte{}, err
}
return data, nil