Skip to content

Commit

Permalink
Remove ioutil (#1096)
Browse files Browse the repository at this point in the history
Signed-off-by: inosato <si17_21@yahoo.co.jp>
  • Loading branch information
inosato committed Aug 2, 2022
1 parent 76cdae2 commit 44c2c4d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions api/prometheus/v1/api_test.go
Expand Up @@ -17,7 +17,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"math"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -1680,7 +1680,7 @@ func (c *httpTestClient) Do(ctx context.Context, req *http.Request) (*http.Respo
var body []byte
done := make(chan struct{})
go func() {
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
close(done)
}()

Expand Down
3 changes: 1 addition & 2 deletions prometheus/process_collector.go
Expand Up @@ -16,7 +16,6 @@ package prometheus
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -152,7 +151,7 @@ func (c *processCollector) reportError(ch chan<- Metric, desc *Desc, err error)
// It is meant to be used for the PidFn field in ProcessCollectorOpts.
func NewPidFileFn(pidFilePath string) func() (int, error) {
return func() (int, error) {
content, err := ioutil.ReadFile(pidFilePath)
content, err := os.ReadFile(pidFilePath)
if err != nil {
return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err)
}
Expand Down
6 changes: 3 additions & 3 deletions prometheus/push/push.go
Expand Up @@ -40,7 +40,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -245,7 +245,7 @@ func (p *Pusher) Delete() error {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusAccepted {
body, _ := ioutil.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
body, _ := io.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
return fmt.Errorf("unexpected status code %d while deleting %s: %s", resp.StatusCode, p.fullURL(), body)
}
return nil
Expand Down Expand Up @@ -297,7 +297,7 @@ func (p *Pusher) push(ctx context.Context, method string) error {
defer resp.Body.Close()
// Depending on version and configuration of the PGW, StatusOK or StatusAccepted may be returned.
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {
body, _ := ioutil.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
body, _ := io.ReadAll(resp.Body) // Ignore any further error as this is for an error message only.
return fmt.Errorf("unexpected status code %d while pushing to %s: %s", resp.StatusCode, p.fullURL(), body)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions prometheus/push/push_test.go
Expand Up @@ -15,7 +15,7 @@ package push

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -38,7 +38,7 @@ func TestPush(t *testing.T) {
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
lastMethod = r.Method
var err error
lastBody, err = ioutil.ReadAll(r.Body)
lastBody, err = io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions prometheus/registry.go
Expand Up @@ -16,7 +16,6 @@ package prometheus
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -563,7 +562,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
// This is intended for use with the textfile collector of the node exporter.
// Note that the node exporter expects the filename to be suffixed with ".prom".
func WriteToTextfile(filename string, g Gatherer) error {
tmp, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
tmp, err := os.CreateTemp(filepath.Dir(filename), filepath.Base(filename))
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions prometheus/registry_test.go
Expand Up @@ -23,7 +23,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -1066,7 +1065,7 @@ test_summary_count{name="foo"} 2
gauge.With(prometheus.Labels{"name": "baz"}).Set(1.1)
counter.With(prometheus.Labels{"name": "qux"}).Inc()

tmpfile, err := ioutil.TempFile("", "prom_registry_test")
tmpfile, err := os.CreateTemp("", "prom_registry_test")
if err != nil {
t.Fatal(err)
}
Expand All @@ -1076,7 +1075,7 @@ test_summary_count{name="foo"} 2
t.Fatal(err)
}

fileBytes, err := ioutil.ReadFile(tmpfile.Name())
fileBytes, err := os.ReadFile(tmpfile.Name())
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 44c2c4d

Please sign in to comment.