Skip to content

Commit

Permalink
refactor: move from io/ioutil to io and os packages (#647)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Juneezee authored Nov 13, 2021
1 parent 3a3de3c commit da4e374
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
3 changes: 1 addition & 2 deletions v3/cmd/zlint-gtld-update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"go/format"
"html/template"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -138,7 +137,7 @@ func getData(url string) ([]byte, error) {
url, http.StatusOK, resp.StatusCode)
}

respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unexpected error reading response "+
"body from %q : %s",
Expand Down
4 changes: 2 additions & 2 deletions v3/cmd/zlint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/pem"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -130,7 +130,7 @@ func main() {
}

func doLint(inputFile *os.File, inform string, registry lint.Registry) {
fileBytes, err := ioutil.ReadAll(inputFile)
fileBytes, err := io.ReadAll(inputFile)
if err != nil {
log.Fatalf("unable to read file %s: %s", inputFile.Name(), err)
}
Expand Down
9 changes: 4 additions & 5 deletions v3/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -74,12 +73,12 @@ func (f dataFile) DownloadTo(dir string) error {
reader = bzip2.NewReader(reader)
}

dataBytes, err := ioutil.ReadAll(reader)
dataBytes, err := io.ReadAll(reader)
if err != nil {
return err
}

if err := ioutil.WriteFile(p, dataBytes, 0644); err != nil {
if err := os.WriteFile(p, dataBytes, 0644); err != nil {
return err
}

Expand All @@ -97,7 +96,7 @@ type config struct {
// the given file or returns an error if reading or unmarshaling the config file
// fails.
func loadConfig(file string) (*config, error) {
jsonBytes, err := ioutil.ReadFile(file)
jsonBytes, err := os.ReadFile(file)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -151,7 +150,7 @@ func (c *config) Save(file string) error {
return err
}

return ioutil.WriteFile(file, jsonBytes, 0644)
return os.WriteFile(file, jsonBytes, 0644)
}

// Valid returns an error if the config has an empty CacheDir, no Files, or if
Expand Down
4 changes: 2 additions & 2 deletions v3/integration/lints/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -161,7 +161,7 @@ func Parse(path string) (*ast.File, *File, error) {
if err != nil {
return nil, nil, err
}
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions v3/integration/lints/lints/not_committing_genTestCerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"crypto/sha256"
"fmt"
"go/ast"
"io/ioutil"
"os"
"strings"

"github.com/zmap/zlint/v3/integration/lints/lint"
Expand All @@ -33,7 +33,7 @@ func (i *NotCommittingGenTestCerts) CheckApplies(tree *ast.File, file *lint.File
}

func (i *NotCommittingGenTestCerts) Lint(tree *ast.File, file *lint.File) *lint.Result {
contents, err := ioutil.ReadFile(file.Path)
contents, err := os.ReadFile(file.Path)
if err != nil {
return lint.NewResult(fmt.Sprintf("failed to open %s", file.Name))
}
Expand Down
3 changes: 1 addition & 2 deletions v3/lints/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lints
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -32,7 +31,7 @@ func checkForLeftovers(filename string) error {
"Change this to match source TEXT",
}

src, err := ioutil.ReadFile(filename)
src, err := os.ReadFile(filename)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions v3/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package test
import (
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/zmap/zcrypto/x509"
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestLintCert(lintName string, cert *x509.Certificate) *lint.LintResult {
func ReadTestCert(inPath string) *x509.Certificate {
fullPath := fmt.Sprintf("../../testdata/%s", inPath)

data, err := ioutil.ReadFile(fullPath)
data, err := os.ReadFile(fullPath)
if err != nil {
panic(fmt.Sprintf(
"Unable to read test certificate from %q - %q "+
Expand Down

0 comments on commit da4e374

Please sign in to comment.