From b34402706535aee144dcd8f2e0b6414803f7bb20 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Fri, 17 Nov 2023 17:33:08 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil --- clickhouse.go | 4 ++-- dump.go | 7 +++---- server.go | 4 ++-- server_test.go | 6 +++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/clickhouse.go b/clickhouse.go index 10c80e6..c7dd10e 100644 --- a/clickhouse.go +++ b/clickhouse.go @@ -4,7 +4,7 @@ import ( "crypto/tls" "errors" "fmt" - "io/ioutil" + "io" "log" "net/http" "strings" @@ -205,7 +205,7 @@ func (srv *ClickhouseServer) SendQuery(r *ClickhouseRequest) (response string, s if r.isInsert && srv.LogQueries { log.Printf("INFO: sent %+v rows to %+v of %+v\n", r.Count, srv.URL, r.Query) } - buf, _ := ioutil.ReadAll(resp.Body) + buf, _ := io.ReadAll(resp.Body) s := string(buf) if resp.StatusCode >= 502 { srv.Bad = true diff --git a/dump.go b/dump.go index 0f82d3f..f35bb3a 100644 --- a/dump.go +++ b/dump.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "io/ioutil" "log" "os" "path" @@ -75,7 +74,7 @@ func (d *FileDumper) Dump(params string, content string, response string, prefix } d.DumpNum++ file_path := path.Join(d.Path, d.dumpName(d.DumpNum, prefix, status)) - err = ioutil.WriteFile(file_path, []byte(data), 0644) + err = os.WriteFile(file_path, []byte(data), 0644) if err != nil { log.Printf("ERROR: dump to file: %+v\n", err) } else { @@ -94,7 +93,7 @@ func (d *FileDumper) GetDump() (string, error) { return "", err } - files, err := ioutil.ReadDir(d.Path) + files, err := os.ReadDir(d.Path) if err != nil { log.Fatal(err) } @@ -120,7 +119,7 @@ func (d *FileDumper) GetDump() (string, error) { // GetDumpData - get dump data from filesystem func (d *FileDumper) GetDumpData(id string) (data string, response string, err error) { path := d.makePath(id) - s, err := ioutil.ReadFile(path) + s, err := os.ReadFile(path) items := strings.Split(string(s), dumpResponseMark) if len(items) > 1 { return items[0], items[1], err diff --git a/server.go b/server.go index df45553..b1f4188 100644 --- a/server.go +++ b/server.go @@ -2,7 +2,7 @@ package main import ( "context" - "io/ioutil" + "io" "log" "net/http" "os" @@ -42,7 +42,7 @@ func NewServer(listen string, collector *Collector, debug bool, logQueries bool) } func (server *Server) writeHandler(c echo.Context) error { - q, _ := ioutil.ReadAll(c.Request().Body) + q, _ := io.ReadAll(c.Request().Body) s := string(q) if server.Debug { diff --git a/server_test.go b/server_test.go index c383f7c..8e37fa5 100644 --- a/server_test.go +++ b/server_test.go @@ -3,7 +3,7 @@ package main import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -90,7 +90,7 @@ func TestServer_MultiServer(t *testing.T) { s1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "") - req, _ := ioutil.ReadAll(r.Body) + req, _ := io.ReadAll(r.Body) mu.Lock() defer mu.Unlock() received = append(received, string(req)) @@ -99,7 +99,7 @@ func TestServer_MultiServer(t *testing.T) { s2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "") - req, _ := ioutil.ReadAll(r.Body) + req, _ := io.ReadAll(r.Body) mu.Lock() defer mu.Unlock() received = append(received, string(req))