all: remove the remaining bits of io/ioutil

The io/ioutil package is deprecated since Go1.16 - see https://tip.golang.org/doc/go1.16#ioutil

VictoriaMetrics requires at least Go1.18, so it is time to remove the io/ioutil from source code

This is a follow-up for 02ca2342ab
This commit is contained in:
Aliaksandr Valialkin 2022-08-22 00:20:55 +03:00
parent 1f89278d88
commit 343241680b
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
4 changed files with 9 additions and 12 deletions

View file

@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"testing" "testing"
@ -87,7 +86,7 @@ groups:
` `
) )
f, err := ioutil.TempFile("", "") f, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -2,7 +2,6 @@ package notifier
import ( import (
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -12,7 +11,7 @@ import (
) )
func TestConfigWatcherReload(t *testing.T) { func TestConfigWatcherReload(t *testing.T) {
f, err := ioutil.TempFile("", "") f, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -34,7 +33,7 @@ static_configs:
t.Fatalf("expected to have 2 notifiers; got %d %#v", len(ns), ns) t.Fatalf("expected to have 2 notifiers; got %d %#v", len(ns), ns)
} }
f2, err := ioutil.TempFile("", "") f2, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -61,7 +60,7 @@ func TestConfigWatcherStart(t *testing.T) {
consulSDServer := newFakeConsulServer() consulSDServer := newFakeConsulServer()
defer consulSDServer.Close() defer consulSDServer.Close()
consulSDFile, err := ioutil.TempFile("", "") consulSDFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -107,7 +106,7 @@ func TestConfigWatcherReloadConcurrent(t *testing.T) {
consulSDServer2 := newFakeConsulServer() consulSDServer2 := newFakeConsulServer()
defer consulSDServer2.Close() defer consulSDServer2.Close()
consulSDFile, err := ioutil.TempFile("", "") consulSDFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -123,7 +122,7 @@ consul_sd_configs:
- consul - consul
`, consulSDServer1.URL, consulSDServer2.URL)) `, consulSDServer1.URL, consulSDServer2.URL))
staticAndConsulSDFile, err := ioutil.TempFile("", "") staticAndConsulSDFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -17,7 +17,7 @@ import (
"errors" "errors"
"fmt" "fmt"
htmlTpl "html/template" htmlTpl "html/template"
"io/ioutil" "io"
"math" "math"
"net" "net"
"net/url" "net/url"
@ -71,7 +71,7 @@ func Load(pathPatterns []string, overwrite bool) error {
} }
} }
if len(tmpl.Templates()) > 0 { if len(tmpl.Templates()) > 0 {
err := tmpl.Execute(ioutil.Discard, nil) err := tmpl.Execute(io.Discard, nil)
if err != nil { if err != nil {
return fmt.Errorf("failed to execute template: %w", err) return fmt.Errorf("failed to execute template: %w", err)
} }

View file

@ -2,7 +2,6 @@ package netstorage
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"sync" "sync"
@ -109,7 +108,7 @@ func (tbf *tmpBlocksFile) WriteBlockRefData(b []byte) (tmpBlockAddr, error) {
// Slow path: flush the data from tbf.buf to file. // Slow path: flush the data from tbf.buf to file.
if tbf.f == nil { if tbf.f == nil {
f, err := ioutil.TempFile(tmpBlocksDir, "") f, err := os.CreateTemp(tmpBlocksDir, "")
if err != nil { if err != nil {
return addr, err return addr, err
} }