Skip to content

Commit 44c2c4d

Browse files
authored
Remove ioutil (#1096)
Signed-off-by: inosato <[email protected]>
1 parent 76cdae2 commit 44c2c4d

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

api/prometheus/v1/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"context"
1818
"errors"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"math"
2222
"net/http"
2323
"net/http/httptest"
@@ -1680,7 +1680,7 @@ func (c *httpTestClient) Do(ctx context.Context, req *http.Request) (*http.Respo
16801680
var body []byte
16811681
done := make(chan struct{})
16821682
go func() {
1683-
body, err = ioutil.ReadAll(resp.Body)
1683+
body, err = io.ReadAll(resp.Body)
16841684
close(done)
16851685
}()
16861686

prometheus/process_collector.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package prometheus
1616
import (
1717
"errors"
1818
"fmt"
19-
"io/ioutil"
2019
"os"
2120
"strconv"
2221
"strings"
@@ -152,7 +151,7 @@ func (c *processCollector) reportError(ch chan<- Metric, desc *Desc, err error)
152151
// It is meant to be used for the PidFn field in ProcessCollectorOpts.
153152
func NewPidFileFn(pidFilePath string) func() (int, error) {
154153
return func() (int, error) {
155-
content, err := ioutil.ReadFile(pidFilePath)
154+
content, err := os.ReadFile(pidFilePath)
156155
if err != nil {
157156
return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err)
158157
}

prometheus/push/push.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
"encoding/base64"
4141
"errors"
4242
"fmt"
43-
"io/ioutil"
43+
"io"
4444
"net/http"
4545
"net/url"
4646
"strings"
@@ -245,7 +245,7 @@ func (p *Pusher) Delete() error {
245245
}
246246
defer resp.Body.Close()
247247
if resp.StatusCode != http.StatusAccepted {
248-
body, _ := ioutil.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
248+
body, _ := io.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
249249
return fmt.Errorf("unexpected status code %d while deleting %s: %s", resp.StatusCode, p.fullURL(), body)
250250
}
251251
return nil
@@ -297,7 +297,7 @@ func (p *Pusher) push(ctx context.Context, method string) error {
297297
defer resp.Body.Close()
298298
// Depending on version and configuration of the PGW, StatusOK or StatusAccepted may be returned.
299299
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {
300-
body, _ := ioutil.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
300+
body, _ := io.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
301301
return fmt.Errorf("unexpected status code %d while pushing to %s: %s", resp.StatusCode, p.fullURL(), body)
302302
}
303303
return nil

prometheus/push/push_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package push
1515

1616
import (
1717
"bytes"
18-
"io/ioutil"
18+
"io"
1919
"net/http"
2020
"net/http/httptest"
2121
"testing"
@@ -38,7 +38,7 @@ func TestPush(t *testing.T) {
3838
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3939
lastMethod = r.Method
4040
var err error
41-
lastBody, err = ioutil.ReadAll(r.Body)
41+
lastBody, err = io.ReadAll(r.Body)
4242
if err != nil {
4343
t.Fatal(err)
4444
}

prometheus/registry.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package prometheus
1616
import (
1717
"bytes"
1818
"fmt"
19-
"io/ioutil"
2019
"os"
2120
"path/filepath"
2221
"runtime"
@@ -563,7 +562,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
563562
// This is intended for use with the textfile collector of the node exporter.
564563
// Note that the node exporter expects the filename to be suffixed with ".prom".
565564
func WriteToTextfile(filename string, g Gatherer) error {
566-
tmp, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
565+
tmp, err := os.CreateTemp(filepath.Dir(filename), filepath.Base(filename))
567566
if err != nil {
568567
return err
569568
}

prometheus/registry_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"bytes"
2424
"errors"
2525
"fmt"
26-
"io/ioutil"
2726
"math/rand"
2827
"net/http"
2928
"net/http/httptest"
@@ -1066,7 +1065,7 @@ test_summary_count{name="foo"} 2
10661065
gauge.With(prometheus.Labels{"name": "baz"}).Set(1.1)
10671066
counter.With(prometheus.Labels{"name": "qux"}).Inc()
10681067

1069-
tmpfile, err := ioutil.TempFile("", "prom_registry_test")
1068+
tmpfile, err := os.CreateTemp("", "prom_registry_test")
10701069
if err != nil {
10711070
t.Fatal(err)
10721071
}
@@ -1076,7 +1075,7 @@ test_summary_count{name="foo"} 2
10761075
t.Fatal(err)
10771076
}
10781077

1079-
fileBytes, err := ioutil.ReadFile(tmpfile.Name())
1078+
fileBytes, err := os.ReadFile(tmpfile.Name())
10801079
if err != nil {
10811080
t.Fatal(err)
10821081
}

0 commit comments

Comments
 (0)