Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
testwill committed Sep 4, 2023
1 parent 521f736 commit aa95e4a
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 78 deletions.
6 changes: 3 additions & 3 deletions analytics/attribs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package analytics

import (
"io/ioutil"
"os"
"testing"

"github.com/simagix/keyhole/ftdc"
Expand All @@ -13,7 +13,7 @@ func TestGetServerStatusDataPoints(t *testing.T) {
var err error
var buffer []byte

if buffer, err = ioutil.ReadFile(DiagnosticDataFilename); err != nil {
if buffer, err = os.ReadFile(DiagnosticDataFilename); err != nil {
t.Fatal(err)
}
metrics := ftdc.NewMetrics()
Expand All @@ -27,7 +27,7 @@ func TestGetSystemMetricsDataPoints(t *testing.T) {
var err error
var buffer []byte

if buffer, err = ioutil.ReadFile(DiagnosticDataFilename); err != nil {
if buffer, err = os.ReadFile(DiagnosticDataFilename); err != nil {
t.Fatal(err)
}
metrics := ftdc.NewMetrics()
Expand Down
7 changes: 3 additions & 4 deletions analytics/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -129,10 +128,10 @@ func (d *DiagnosticData) PrintDiagnosticData(filenames []string) (string, error)
// readDiagnosticDir reads diagnotics.data from a directory
func (d *DiagnosticData) readDiagnosticDir(dirname string) error {
var err error
var files []os.FileInfo
var files []os.DirEntry
var filenames []string

if files, err = ioutil.ReadDir(dirname); err != nil {
if files, err = os.ReadDir(dirname); err != nil {
return err
}

Expand Down Expand Up @@ -218,7 +217,7 @@ func (d *DiagnosticData) readDiagnosticFile(filename string) (DiagnosticData, er
if r, err = gox.NewFileReader(filename); err != nil {
return diagData, err
}
if buffer, err = ioutil.ReadAll(r); err != nil {
if buffer, err = io.ReadAll(r); err != nil {
return diagData, err
}

Expand Down
5 changes: 2 additions & 3 deletions analytics/diagnostic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package analytics

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -14,10 +13,10 @@ const DiagnosticDataFilename = DiagnosticDataDirectory + "/metrics.2017-10-12T20

func TestReadDiagnosticFiles(t *testing.T) {
var err error
var files []os.FileInfo
var files []os.DirEntry
var filenames []string

if files, err = ioutil.ReadDir(DiagnosticDataDirectory); err != nil {
if files, err = os.ReadDir(DiagnosticDataDirectory); err != nil {
t.Fatal(err)
}

Expand Down
4 changes: 2 additions & 2 deletions analytics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -131,7 +131,7 @@ func (m *Metrics) readProcessedFTDC(infile string) error {
if reader, err = gox.NewReader(file); err != nil {
return err
}
if data, err = ioutil.ReadAll(reader); err != nil {
if data, err = io.ReadAll(reader); err != nil {
return err
}
buffer := bytes.NewBuffer(data)
Expand Down
3 changes: 1 addition & 2 deletions analytics/metrics_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package analytics

import (
"errors"
"io/ioutil"
"os"
"strings"
"time"
Expand All @@ -20,7 +19,7 @@ func getFilenames(filenames []string) []string {
}
switch mode := fi.Mode(); {
case mode.IsDir():
files, _ := ioutil.ReadDir(filename)
files, _ := os.ReadDir(filename)
for _, file := range files {
if !file.IsDir() &&
(strings.HasPrefix(file.Name(), "metrics.") || strings.HasPrefix(file.Name(), "keyhole_stats.")) {
Expand Down
3 changes: 1 addition & 2 deletions analytics/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package analytics

import (
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
Expand All @@ -27,7 +26,7 @@ func GetMetricsFilenames(filenames []string) []string {
}
switch mode := fi.Mode(); {
case mode.IsDir():
files, _ := ioutil.ReadDir(filename)
files, _ := os.ReadDir(filename)
for _, file := range files {
if !file.IsDir() &&
(strings.HasPrefix(file.Name(), "metrics.") || strings.HasPrefix(file.Name(), "keyhole_stats.")) {
Expand Down
7 changes: 4 additions & 3 deletions atlas/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"

"github.com/simagix/gox"
)
Expand All @@ -31,7 +32,7 @@ func (api *API) AlertsDo(method string, data string) (string, error) {
return "", err
}
defer resp.Body.Close()
b, err = ioutil.ReadAll(resp.Body)
b, err = io.ReadAll(resp.Body)
json.Unmarshal(b, &doc)
return gox.Stringify(doc, "", " "), err
}
Expand All @@ -42,7 +43,7 @@ func (api *API) AddAlerts(filename string) (string, error) {
var buf []byte
var str string
var alerts []map[string]interface{}
if buf, err = ioutil.ReadFile(filename); err != nil {
if buf, err = os.ReadFile(filename); err != nil {
return "", err
}

Expand Down
6 changes: 3 additions & 3 deletions atlas/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -158,7 +158,7 @@ func (api *API) Get(uri string) ([]byte, error) {
return b, err
}
defer resp.Body.Close()
b, err = ioutil.ReadAll(resp.Body)
b, err = io.ReadAll(resp.Body)
return b, err
}

Expand All @@ -175,7 +175,7 @@ func (api *API) Patch(uri string, body []byte) ([]byte, error) {
return b, err
}
defer resp.Body.Close()
b, err = ioutil.ReadAll(resp.Body)
b, err = io.ReadAll(resp.Body)
return b, err
}

Expand Down
4 changes: 2 additions & 2 deletions atlas/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/simagix/gox"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (api *API) ClustersDo(method string, data string) (string, error) {
return "", err
}
defer resp.Body.Close()
b, err = ioutil.ReadAll(resp.Body)
b, err = io.ReadAll(resp.Body)
json.Unmarshal(b, &doc)
return gox.Stringify(doc, "", " "), err
}
5 changes: 2 additions & 3 deletions atlas/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package atlas
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
)
Expand All @@ -28,7 +27,7 @@ func TestGetClusters(t *testing.T) {
}
os.Mkdir("./out", 0755)
ofile := `./out/clusters.json`
if err = ioutil.WriteFile(ofile, data, 0644); err != nil {
if err = os.WriteFile(ofile, data, 0644); err != nil {
t.Fatal(err)
}
}
Expand All @@ -52,7 +51,7 @@ func TestGetCluster(t *testing.T) {
}
os.Mkdir("./out", 0755)
ofile := fmt.Sprintf(`./out/cluster-%v.json`, clusterName)
if err = ioutil.WriteFile(ofile, data, 0644); err != nil {
if err = os.WriteFile(ofile, data, 0644); err != nil {
t.Fatal(err)
}
}
9 changes: 5 additions & 4 deletions atlas/ftdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -63,7 +64,7 @@ func (api *API) DownloadFTDC() (string, error) {
if resp, err = gox.HTTPDigest("POST", uri, api.publicKey, api.privateKey, headers, body); err != nil {
return "", err
}
body, _ = ioutil.ReadAll(resp.Body)
body, _ = io.ReadAll(resp.Body)
resp.Body.Close()
json.Unmarshal(body, &doc)
if doc["id"] == nil {
Expand All @@ -89,7 +90,7 @@ func (api *API) DownloadFTDC() (string, error) {
body, _ = api.Get(uri)
fname := api.clusterName + "-diagnostic.tar.gz"

ioutil.WriteFile(fname, body, 0644)
os.WriteFile(fname, body, 0644)

// delete the log collection job
uri = BaseURL + "/groups/" + api.groupID + "/logCollectionJobs/" + jobID
Expand All @@ -99,7 +100,7 @@ func (api *API) DownloadFTDC() (string, error) {
return "", err
}
defer resp.Body.Close()
body, _ = ioutil.ReadAll(resp.Body)
body, _ = io.ReadAll(resp.Body)
json.Unmarshal(body, &doc)
fmt.Println(gox.Stringify(doc, "", " "))
return fmt.Sprintf("FTDC archive was written to %v", fname), err
Expand Down
4 changes: 2 additions & 2 deletions atlas/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package atlas
import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"time"

Expand Down Expand Up @@ -85,7 +85,7 @@ func (api *API) DownloadLogs() ([]string, error) {
continue
}
if len(b) > 0 {
if err = ioutil.WriteFile(filename, b, 0644); err != nil {
if err = os.WriteFile(filename, b, 0644); err != nil {
log.Println(err)
continue
}
Expand Down
6 changes: 3 additions & 3 deletions comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
Expand Down Expand Up @@ -56,7 +56,7 @@ func (p *Comparison) Compare(source string, target string) error {
if fd, err = gox.NewFileReader(source); err != nil {
return err
}
if data, err = ioutil.ReadAll(fd); err != nil {
if data, err = io.ReadAll(fd); err != nil {
return err
}
if err = bson.Unmarshal(data, p.SourceStats); err != nil {
Expand All @@ -65,7 +65,7 @@ func (p *Comparison) Compare(source string, target string) error {
if fd, err = gox.NewFileReader(target); err != nil {
return err
}
if data, err = ioutil.ReadAll(fd); err != nil {
if data, err = io.ReadAll(fd); err != nil {
return err
}
if err = bson.Unmarshal(data, p.TargetStats); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package keyhole

import (
"fmt"
"io/ioutil"
"os"

"github.com/simagix/gox"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -43,7 +43,7 @@ func Exec(filename string, signature string) error {
var err error
var cfg *Config
var data []byte
if data, err = ioutil.ReadFile(filename); err != nil {
if data, err = os.ReadFile(filename); err != nil {
return err
} else if err = bson.UnmarshalExtJSON(data, false, &cfg); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions ftdc/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package ftdc

import (
"io/ioutil"
"os"
"testing"

"go.mongodb.org/mongo-driver/bson"
Expand All @@ -15,7 +15,7 @@ func TestDecode(t *testing.T) {
var err error
var buffer []byte

if buffer, err = ioutil.ReadFile(filename); err != nil {
if buffer, err = os.ReadFile(filename); err != nil {
t.Fatal(err)
}
m := NewMetrics()
Expand All @@ -33,7 +33,7 @@ func TestTraverseDocElem(t *testing.T) {
var err error
var buffer []byte

if buffer, err = ioutil.ReadFile(filename); err != nil {
if buffer, err = os.ReadFile(filename); err != nil {
t.Fatal(err)
}
m := NewMetrics()
Expand Down
3 changes: 1 addition & 2 deletions ftdc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bytes"
"compress/zlib"
"io"
"io/ioutil"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
Expand Down Expand Up @@ -41,7 +40,7 @@ func (m *Metrics) ReadAllMetrics(data *[]byte) error {
return err
}
var block []byte
if block, err = ioutil.ReadAll(r); err != nil {
if block, err = io.ReadAll(r); err != nil {
return err
}
if md, err = m.decode(block); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions ftdc/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
package ftdc

import (
"io/ioutil"
"os"
"testing"
)

func TestReadAllMetrics(t *testing.T) {
var err error
var buffer []byte
if buffer, err = ioutil.ReadFile(filename); err != nil {
if buffer, err = os.ReadFile(filename); err != nil {
t.Fatal(err)
}
m := NewMetrics()
Expand Down
Loading

0 comments on commit aa95e4a

Please sign in to comment.