refactor: move from io/ioutil to io and os packages (#1068)

* refactor: move from io/ioutil to io and os packages

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* build: update snapcraft `go-channel` to 1.17

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun 2022-01-21 16:50:53 +08:00 committed by GitHub
parent f8bcaca4c9
commit e347090571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 10 deletions

View File

@ -18,6 +18,14 @@ linters:
- revive - revive
- unconvert - unconvert
- unparam - unparam
linters-settings:
depguard:
list-type: blacklist
include-go-root: true
packages:
- io/ioutil
packages-with-error-message:
- io/ioutil: "The 'io/ioutil' package is deprecated. Use corresponding 'os' or 'io' functions instead."
issues: issues:
exclude-rules: exclude-rules:
- linters: - linters:

View File

@ -3,7 +3,6 @@ package yqlib
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
) )
@ -77,7 +76,7 @@ func createTempFile() (*os.File, error) {
return nil, err return nil, err
} }
file, err := ioutil.TempFile("", "temp") file, err := os.CreateTemp("", "temp")
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,7 +1,8 @@
package yqlib package yqlib
import ( import (
"io/ioutil" "io"
"os"
"testing" "testing"
"github.com/mikefarah/yq/v4/test" "github.com/mikefarah/yq/v4/test"
@ -24,7 +25,7 @@ func createTestFile(content string) string {
} }
func readFile(filename string) string { func readFile(filename string) string {
bytes, err := ioutil.ReadFile(filename) bytes, err := os.ReadFile(filename)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -60,7 +61,7 @@ yaml: doc
test.AssertResult(t, expectedYamlFm, yamlFm) test.AssertResult(t, expectedYamlFm, yamlFm)
contentBytes, err := ioutil.ReadAll(fmHandler.GetContentReader()) contentBytes, err := io.ReadAll(fmHandler.GetContentReader())
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -97,7 +98,7 @@ yaml: doc
test.AssertResult(t, expectedYamlFm, yamlFm) test.AssertResult(t, expectedYamlFm, yamlFm)
contentBytes, err := ioutil.ReadAll(fmHandler.GetContentReader()) contentBytes, err := io.ReadAll(fmHandler.GetContentReader())
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -131,7 +132,7 @@ yaml: doc
test.AssertResult(t, expectedYamlFm, yamlFm) test.AssertResult(t, expectedYamlFm, yamlFm)
contentBytes, err := ioutil.ReadAll(fmHandler.GetContentReader()) contentBytes, err := io.ReadAll(fmHandler.GetContentReader())
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"container/list" "container/list"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@ -19,7 +18,7 @@ func loadString(filename string) (*CandidateNode, error) {
// ignore CWE-22 gosec issue - that's more targeted for http based apps that run in a public directory, // ignore CWE-22 gosec issue - that's more targeted for http based apps that run in a public directory,
// and ensuring that it's not possible to give a path to a file outside that directory. // and ensuring that it's not possible to give a path to a file outside that directory.
filebytes, err := ioutil.ReadFile(filename) // #nosec filebytes, err := os.ReadFile(filename) // #nosec
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -16,7 +16,7 @@ apps:
parts: parts:
yq: yq:
plugin: go plugin: go
go-channel: 1.15/stable go-channel: 1.17/stable
source: . source: .
source-type: git source-type: git
go-importpath: github.com/mikefarah/yq go-importpath: github.com/mikefarah/yq