Skip to content

Commit

Permalink
chore: Update ioutil package to io / os packages. (sourcenetwork#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone authored Apr 26, 2022
1 parent 727b7e2 commit c833795
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package http
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"

"github.com/multiformats/go-multihash"
Expand Down Expand Up @@ -105,7 +105,7 @@ func (s *Server) execGQL(w http.ResponseWriter, r *http.Request) {
func (s *Server) loadSchema(w http.ResponseWriter, r *http.Request) {
ctx := context.Background()
var result client.QueryResult
sdl, err := ioutil.ReadAll(r.Body)
sdl, err := io.ReadAll(r.Body)

defer func() {
err = r.Body.Close()
Expand Down
4 changes: 2 additions & 2 deletions cli/defradb/cmd/blocks_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -56,7 +56,7 @@ var getCmd = &cobra.Command{
}
}()

buf, err := ioutil.ReadAll(res.Body)
buf, err := io.ReadAll(res.Body)
if err != nil {
log.ErrorE(ctx, "request failed", err)
return
Expand Down
4 changes: 2 additions & 2 deletions cli/defradb/cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -51,7 +51,7 @@ var dumpCmd = &cobra.Command{
}
}()

buf, err := ioutil.ReadAll(res.Body)
buf, err := io.ReadAll(res.Body)
if err != nil {
log.ErrorE(ctx, "request failed", err)
return
Expand Down
4 changes: 2 additions & 2 deletions cli/defradb/cmd/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -52,7 +52,7 @@ var pingCmd = &cobra.Command{
}
}()

buf, err := ioutil.ReadAll(res.Body)
buf, err := io.ReadAll(res.Body)
if err != nil {
log.ErrorE(ctx, "request failed", err)
return
Expand Down
4 changes: 2 additions & 2 deletions cli/defradb/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -83,7 +83,7 @@ the additional documentation found at: https://hackmd.io/@source/BksQY6Qfw.
}
}()

buf, err := ioutil.ReadAll(res.Body)
buf, err := io.ReadAll(res.Body)
if err != nil {
log.ErrorE(ctx, "request failed", err)
return
Expand Down
7 changes: 4 additions & 3 deletions cli/defradb/cmd/schema_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
"strings"

"github.com/sourcenetwork/defradb/logging"
Expand All @@ -42,7 +43,7 @@ var addCmd = &cobra.Command{
if len(args) > 0 {
schema = []byte(strings.Join(args, "\n"))
} else if schemaFile != "" {
buf, err := ioutil.ReadFile(schemaFile)
buf, err := os.ReadFile(schemaFile)
cobra.CheckErr(err)
schema = buf
} else {
Expand Down Expand Up @@ -70,7 +71,7 @@ var addCmd = &cobra.Command{
}
}()

result, err := ioutil.ReadAll(res.Body)
result, err := io.ReadAll(res.Body)
cobra.CheckErr(err)
log.Info(ctx, "", logging.NewKV("Result", string(result)))
},
Expand Down
9 changes: 4 additions & 5 deletions db/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"context"
"fmt"
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -690,7 +689,7 @@ func checkIfDatabaseFormatChangesAreDocumented() bool {
return false
}

func getDatabaseFormatDocumentation(startPath string, allowDescend bool) ([]fs.FileInfo, bool) {
func getDatabaseFormatDocumentation(startPath string, allowDescend bool) ([]fs.DirEntry, bool) {
startInfo, err := os.Stat(startPath)
if err != nil {
panic(err)
Expand All @@ -704,15 +703,15 @@ func getDatabaseFormatDocumentation(startPath string, allowDescend bool) ([]fs.F
}

for {
directoryContents, err := ioutil.ReadDir(currentDirectory)
directoryContents, err := os.ReadDir(currentDirectory)
if err != nil {
panic(err)
}

for _, directoryItem := range directoryContents {
directoryItemPath := path.Join(currentDirectory, directoryItem.Name())
if directoryItem.Name() == documentationDirectoryName {
probableFormatChangeDirectoryContents, err := ioutil.ReadDir(directoryItemPath)
probableFormatChangeDirectoryContents, err := os.ReadDir(directoryItemPath)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -741,7 +740,7 @@ func getDatabaseFormatDocumentation(startPath string, allowDescend bool) ([]fs.F
panic("Database documentation directory not found")
}
} else {
return []fs.FileInfo{}, false
return []fs.DirEntry{}, false
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package node

import (
"context"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -179,14 +178,14 @@ func getHostKey(keypath string) (crypto.PrivKey, error) {
if err := os.MkdirAll(keypath, os.ModePerm); err != nil {
return nil, err
}
if err = ioutil.WriteFile(pth, bytes, 0400); err != nil {
if err = os.WriteFile(pth, bytes, 0400); err != nil {
return nil, err
}
return key, nil
} else if err != nil {
return nil, err
} else {
bytes, err := ioutil.ReadFile(pth)
bytes, err := os.ReadFile(pth)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion tools/configs/golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ linters-settings:
# [deprecated] comma-separated list of pairs of the form pkg:regex
# the regex is used to ignore names within pkg. (default "fmt:.*").
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
ignore: fmt:.*,io/ioutil:^Read.*
ignore: fmt:.*

# [deprecated] use exclude-functions instead.
# path to a file containing a list of functions to exclude from checking
Expand Down

0 comments on commit c833795

Please sign in to comment.