Skip to content

Commit df01a9d

Browse files
committed
Removed depricated io/ioutil functions
1 parent 08c1f1d commit df01a9d

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

cmd/config.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package cmd
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423

@@ -94,7 +93,7 @@ var configViewCmd = &cobra.Command{
9493
Display the contents of the contents of ~/.kubewatch.yaml`,
9594
Run: func(cmd *cobra.Command, args []string) {
9695
fmt.Fprintln(os.Stderr, "Contents of ~/.kubewatch.yaml")
97-
configFile, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), kubewatchConfigFile))
96+
configFile, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), kubewatchConfigFile))
9897
if err != nil {
9998
fmt.Fprintf(os.Stderr, "%v\n", err)
10099
os.Exit(1)

config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
package config
2020

2121
import (
22-
"io/ioutil"
22+
"io"
2323
"os"
2424
"path/filepath"
2525
"runtime"
@@ -237,7 +237,7 @@ func (c *Config) Load() error {
237237
return err
238238
}
239239

240-
b, err := ioutil.ReadAll(file)
240+
b, err := io.ReadAll(file)
241241
if err != nil {
242242
return err
243243
}

pkg/handlers/msteam/msteam.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"github.com/sirupsen/logrus"
24-
"io/ioutil"
24+
"io"
2525
"net/http"
2626
"os"
2727

@@ -98,7 +98,7 @@ func sendCard(ms *MSTeams, card *TeamsMessageCard) (*http.Response, error) {
9898
ms.TeamsWebhookURL, err)
9999
}
100100
if res.StatusCode != http.StatusOK {
101-
resMessage, err := ioutil.ReadAll(res.Body)
101+
resMessage, err := io.ReadAll(res.Body)
102102
if err != nil {
103103
return nil, fmt.Errorf("Failed reading Teams http response: %v", err)
104104
}

pkg/handlers/webhook/webhook.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"crypto/x509"
2222
"fmt"
2323
"github.com/sirupsen/logrus"
24-
"io/ioutil"
2524
"os"
2625

2726
"bytes"
@@ -88,7 +87,7 @@ func (m *Webhook) Init(c *config.Config) error {
8887
if cert == "" {
8988
logrus.Printf("No webhook cert is given")
9089
} else {
91-
caCert, err := ioutil.ReadFile(cert)
90+
caCert, err := os.ReadFile(cert)
9291
if err != nil {
9392
logrus.Printf("%s\n", err)
9493
return err

tools/yannotated/yannotated_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
54
"os"
65
"testing"
76
)
@@ -25,7 +24,7 @@ type Bar struct {
2524
}
2625

2726
func TestMain(t *testing.T) {
28-
tmp, err := ioutil.TempFile("", "")
27+
tmp, err := os.CreateTemp("", "")
2928
if err != nil {
3029
t.Fatal(err)
3130
}
@@ -55,7 +54,7 @@ rebar:
5554
baz: 0
5655
quz: {}
5756
`
58-
b, err := ioutil.ReadFile(tmp.Name())
57+
b, err := os.ReadFile(tmp.Name())
5958
if err != nil {
6059
t.Fatal(err)
6160
}
@@ -66,7 +65,7 @@ quz: {}
6665
}
6766

6867
func TestGo(t *testing.T) {
69-
tmp, err := ioutil.TempFile("", "")
68+
tmp, err := os.CreateTemp("", "")
7069
if err != nil {
7170
t.Fatal(err)
7271
}
@@ -90,7 +89,7 @@ var yannotated = ` + "`" + `# Baz is baz.
9089
baz: 0
9190
` + "`\n"
9291

93-
b, err := ioutil.ReadFile(tmp.Name())
92+
b, err := os.ReadFile(tmp.Name())
9493
if err != nil {
9594
t.Fatal(err)
9695
}

0 commit comments

Comments
 (0)