all: substitute deprecated ioutil methods (#923)

This commit is contained in:
dlstjq7685 2023-06-11 02:25:01 +09:00 committed by GitHub
parent 0d0a508c60
commit 8b20c453e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 23 deletions

View File

@ -45,7 +45,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -1014,7 +1013,7 @@ func RestoreAsset(dir, name string) error {
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
err = os.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}

View File

@ -30,7 +30,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"os/exec"
"sync/atomic"
"time"
@ -70,7 +69,7 @@ func ffmpeg() (stdin io.WriteCloser, stderr io.ReadCloser, err error) {
go func() {
for {
buf, err := ioutil.ReadAll(stderr)
buf, err := io.ReadAll(stderr)
if err != nil {
fmt.Println(err)
}

View File

@ -16,7 +16,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"time"
@ -63,7 +63,7 @@ func checkTravis(robot *gobot.Robot) {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}

View File

@ -2,7 +2,7 @@ package chip
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
@ -119,14 +119,14 @@ func getXIOBase() (baseAddr int, err error) {
}
for _, labelPath := range labels {
label, err := ioutil.ReadFile(labelPath)
label, err := os.ReadFile(labelPath)
if err != nil {
return baseAddr, err
}
if strings.HasPrefix(string(label), expanderID) {
expanderPath, _ := filepath.Split(labelPath)
basePath := filepath.Join(expanderPath, "base")
base, err := ioutil.ReadFile(basePath)
base, err := os.ReadFile(basePath)
if err != nil {
return baseAddr, err
}

View File

@ -3,7 +3,7 @@ package joystick
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/veandco/go-sdl2/sdl"
@ -250,7 +250,7 @@ func (j *Driver) findHatName(id uint8, hat uint8, list []hat) string {
// loadFile load the joystick config from a .json file
func (j *Driver) loadFile() error {
file, e := ioutil.ReadFile(j.configPath)
file, e := os.ReadFile(j.configPath)
if e != nil {
return e
}

View File

@ -3,7 +3,7 @@ package leap
import (
"errors"
"io"
"io/ioutil"
"os"
"strings"
"sync"
"testing"
@ -47,7 +47,7 @@ func initTestLeapMotionDriver() (*Driver, *NullReadWriteCloser) {
d := NewDriver(a)
d.receive = func(ws io.ReadWriteCloser, buf *[]byte) {
file, _ := ioutil.ReadFile("./test/support/example_frame.json")
file, _ := os.ReadFile("./test/support/example_frame.json")
copy(*buf, file)
}
return d, rwc
@ -82,7 +82,7 @@ func TestLeapMotionDriverHalt(t *testing.T) {
func TestLeapMotionDriverParser(t *testing.T) {
d, _ := initTestLeapMotionDriver()
file, _ := ioutil.ReadFile("./test/support/example_frame.json")
file, _ := os.ReadFile("./test/support/example_frame.json")
parsedFrame := d.ParseFrame(file)
if parsedFrame.Hands == nil || parsedFrame.Pointables == nil || parsedFrame.Gestures == nil {

View File

@ -3,7 +3,7 @@ package mqtt
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"os"
"gobot.io/x/gobot/v2"
@ -204,7 +204,7 @@ func (a *Adaptor) newTLSConfig() *tls.Config {
var certpool *x509.CertPool
if len(a.ServerCert()) > 0 {
certpool = x509.NewCertPool()
pemCerts, err := ioutil.ReadFile(a.ServerCert())
pemCerts, err := os.ReadFile(a.ServerCert())
if err == nil {
certpool.AppendCertsFromPEM(pemCerts)
}

View File

@ -25,7 +25,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"os/exec"
"time"
@ -73,7 +73,7 @@ func main() {
go func() {
for {
buf, err := ioutil.ReadAll(ffmpegErr)
buf, err := io.ReadAll(ffmpegErr)
if err != nil {
fmt.Println(err)
}

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
@ -262,7 +262,7 @@ func (s *Adaptor) request(method string, url string, params url.Values) (m map[s
return
}
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return

View File

@ -2,7 +2,6 @@ package system
import (
"fmt"
"io/ioutil"
"os"
"path"
"regexp"
@ -135,7 +134,7 @@ func (fs *MockFilesystem) stat(name string) (os.FileInfo, error) {
_, ok := fs.Files[name]
if ok {
// return file based mock FileInfo
tmpFile, err := ioutil.TempFile("", name)
tmpFile, err := os.CreateTemp("", name)
if err != nil {
return nil, err
}
@ -148,7 +147,7 @@ func (fs *MockFilesystem) stat(name string) (os.FileInfo, error) {
for path := range fs.Files {
if strings.HasPrefix(path, dirName) {
// return dir based mock FileInfo, TempDir don't like "/" in between
tmpDir, err := ioutil.TempDir("", strings.ReplaceAll(name, "/", "_"))
tmpDir, err := os.MkdirTemp("", strings.ReplaceAll(name, "/", "_"))
if err != nil {
return nil, err
}