Remove ioutil (#1096)

Signed-off-by: inosato <si17_21@yahoo.co.jp>
This commit is contained in:
inosato 2022-08-02 17:27:49 +09:00 committed by GitHub
parent 76cdae298e
commit 44c2c4de85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 14 deletions

View File

@ -17,7 +17,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"math" "math"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -1680,7 +1680,7 @@ func (c *httpTestClient) Do(ctx context.Context, req *http.Request) (*http.Respo
var body []byte var body []byte
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
body, err = ioutil.ReadAll(resp.Body) body, err = io.ReadAll(resp.Body)
close(done) close(done)
}() }()

View File

@ -16,7 +16,6 @@ package prometheus
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -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. // It is meant to be used for the PidFn field in ProcessCollectorOpts.
func NewPidFileFn(pidFilePath string) func() (int, error) { func NewPidFileFn(pidFilePath string) func() (int, error) {
return func() (int, error) { return func() (int, error) {
content, err := ioutil.ReadFile(pidFilePath) content, err := os.ReadFile(pidFilePath)
if err != nil { if err != nil {
return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err) return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err)
} }

View File

@ -40,7 +40,7 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -245,7 +245,7 @@ func (p *Pusher) Delete() error {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusAccepted { 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 fmt.Errorf("unexpected status code %d while deleting %s: %s", resp.StatusCode, p.fullURL(), body)
} }
return nil return nil
@ -297,7 +297,7 @@ func (p *Pusher) push(ctx context.Context, method string) error {
defer resp.Body.Close() defer resp.Body.Close()
// Depending on version and configuration of the PGW, StatusOK or StatusAccepted may be returned. // Depending on version and configuration of the PGW, StatusOK or StatusAccepted may be returned.
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted { 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 fmt.Errorf("unexpected status code %d while pushing to %s: %s", resp.StatusCode, p.fullURL(), body)
} }
return nil return nil

View File

@ -15,7 +15,7 @@ package push
import ( import (
"bytes" "bytes"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -38,7 +38,7 @@ func TestPush(t *testing.T) {
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
lastMethod = r.Method lastMethod = r.Method
var err error var err error
lastBody, err = ioutil.ReadAll(r.Body) lastBody, err = io.ReadAll(r.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -16,7 +16,6 @@ package prometheus
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -563,7 +562,7 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
// This is intended for use with the textfile collector of the node exporter. // 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". // Note that the node exporter expects the filename to be suffixed with ".prom".
func WriteToTextfile(filename string, g Gatherer) error { 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 { if err != nil {
return err return err
} }

View File

@ -23,7 +23,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -1066,7 +1065,7 @@ test_summary_count{name="foo"} 2
gauge.With(prometheus.Labels{"name": "baz"}).Set(1.1) gauge.With(prometheus.Labels{"name": "baz"}).Set(1.1)
counter.With(prometheus.Labels{"name": "qux"}).Inc() counter.With(prometheus.Labels{"name": "qux"}).Inc()
tmpfile, err := ioutil.TempFile("", "prom_registry_test") tmpfile, err := os.CreateTemp("", "prom_registry_test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1076,7 +1075,7 @@ test_summary_count{name="foo"} 2
t.Fatal(err) t.Fatal(err)
} }
fileBytes, err := ioutil.ReadFile(tmpfile.Name()) fileBytes, err := os.ReadFile(tmpfile.Name())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }