From 13f1d73ccbd414affe3d72ac714b6d0c2fe5e042 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Fri, 12 Jan 2024 14:59:44 +1300 Subject: [PATCH] fix: remove usage of deprecated package ioutil --- cmd/fdsn-quake-consumer/sc3ml_backload_test.go | 9 +++++---- cmd/fdsn-quake-consumer/sc3ml_test.go | 12 ++++++------ cmd/fdsn-ws-nrt/fdsn_dataselect.go | 12 ++++++------ cmd/fdsn-ws-nrt/routes_test.go | 7 ++++--- cmd/fdsn-ws/fdsn_dataselect.go | 3 +-- cmd/fdsn-ws/fdsn_event.go | 10 +++++----- cmd/fdsn-ws/fdsn_station.go | 5 ++--- cmd/fdsn-ws/server_test.go | 4 ++-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/cmd/fdsn-quake-consumer/sc3ml_backload_test.go b/cmd/fdsn-quake-consumer/sc3ml_backload_test.go index 5ec9bd76..59492df1 100644 --- a/cmd/fdsn-quake-consumer/sc3ml_backload_test.go +++ b/cmd/fdsn-quake-consumer/sc3ml_backload_test.go @@ -1,16 +1,17 @@ +//go:build backload // +build backload package main import ( "database/sql" - "github.com/GeoNet/kit/cfg" - "io/ioutil" "log" "os" "strings" "sync" "testing" + + "github.com/GeoNet/kit/cfg" ) // TestBackload can be used to load SC3ML into the FDSN database. Files are read @@ -37,7 +38,7 @@ func TestBackload(t *testing.T) { var dir = "/work/seiscompml07-to-load" - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { t.Fatal(err) } @@ -70,7 +71,7 @@ func TestBackload(t *testing.T) { defer wg.Done() for f = range in { - b, err = ioutil.ReadFile(f) + b, err = os.ReadFile(f) if err != nil { log.Println(err) continue diff --git a/cmd/fdsn-quake-consumer/sc3ml_test.go b/cmd/fdsn-quake-consumer/sc3ml_test.go index 41aceb30..d4b6f7d4 100644 --- a/cmd/fdsn-quake-consumer/sc3ml_test.go +++ b/cmd/fdsn-quake-consumer/sc3ml_test.go @@ -3,7 +3,7 @@ package main import ( "bytes" "database/sql" - "io/ioutil" + "io" "os" "reflect" "runtime" @@ -17,7 +17,7 @@ var versions = []string{"2015p768477_0.7.xml", "2015p768477_0.8.xml", "2015p7684 func TestEventUnmarshal(t *testing.T) { for _, input := range versions { - b, err := ioutil.ReadFile("etc/" + input) + b, err := os.ReadFile("etc/" + input) if err != nil { t.Fatal(err) } @@ -97,7 +97,7 @@ func TestEventType(t *testing.T) { // input test file is sc3ml 0.7 change the version string below to test each // sc3ml version that is supported. for _, input := range versions { - b, err := ioutil.ReadFile("etc/" + input) + b, err := os.ReadFile("etc/" + input) if err != nil { t.Fatal(err) } @@ -119,7 +119,7 @@ func TestEventType(t *testing.T) { func TestToQuakeMLEvent(t *testing.T) { for _, input := range versions { - b, err := ioutil.ReadFile("etc/" + input) + b, err := os.ReadFile("etc/" + input) if err != nil { t.Fatal(err) } @@ -148,7 +148,7 @@ func TestToQuakeMLEvent(t *testing.T) { } defer f.Close() - if b, err = ioutil.ReadAll(f); err != nil { + if b, err = io.ReadAll(f); err != nil { t.Fatal(err) } @@ -173,7 +173,7 @@ func TestEventSave(t *testing.T) { } defer f.Close() - if b, err = ioutil.ReadAll(f); err != nil { + if b, err = io.ReadAll(f); err != nil { t.Fatal(err) } diff --git a/cmd/fdsn-ws-nrt/fdsn_dataselect.go b/cmd/fdsn-ws-nrt/fdsn_dataselect.go index dd9973bc..27365bc7 100644 --- a/cmd/fdsn-ws-nrt/fdsn_dataselect.go +++ b/cmd/fdsn-ws-nrt/fdsn_dataselect.go @@ -4,17 +4,17 @@ import ( "bytes" "context" "fmt" - "github.com/GeoNet/fdsn/internal/fdsn" - "github.com/GeoNet/kit/metrics" - "github.com/GeoNet/kit/weft" - "github.com/golang/groupcache" - "io/ioutil" "log" "net/http" "os" "regexp" "text/template" "time" + + "github.com/GeoNet/fdsn/internal/fdsn" + "github.com/GeoNet/kit/metrics" + "github.com/GeoNet/kit/weft" + "github.com/golang/groupcache" ) const NO_DATA = 204 @@ -38,7 +38,7 @@ func init() { } fdsnDataselectWadlFile = b.Bytes() - fdsnDataselectIndex, err = ioutil.ReadFile("assets/fdsn-ws-dataselect.html") + fdsnDataselectIndex, err = os.ReadFile("assets/fdsn-ws-dataselect.html") if err != nil { log.Printf("error reading assets/fdsn-ws-dataselect.html: %s", err.Error()) } diff --git a/cmd/fdsn-ws-nrt/routes_test.go b/cmd/fdsn-ws-nrt/routes_test.go index 2fe2a5c5..07676b1d 100644 --- a/cmd/fdsn-ws-nrt/routes_test.go +++ b/cmd/fdsn-ws-nrt/routes_test.go @@ -2,12 +2,13 @@ package main import ( "database/sql" - wt "github.com/GeoNet/kit/weft/wefttest" - "io/ioutil" + "io" "log" "net/http" "net/http/httptest" "testing" + + wt "github.com/GeoNet/kit/weft/wefttest" ) var testServer *httptest.Server @@ -77,7 +78,7 @@ func setup(t *testing.T) { // Silence the logging unless running with // go test -v if !testing.Verbose() { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) } } diff --git a/cmd/fdsn-ws/fdsn_dataselect.go b/cmd/fdsn-ws/fdsn_dataselect.go index 237e1c50..07bd2d53 100644 --- a/cmd/fdsn-ws/fdsn_dataselect.go +++ b/cmd/fdsn-ws/fdsn_dataselect.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -61,7 +60,7 @@ func init() { } fdsnDataselectWadlFile = b.Bytes() - fdsnDataselectIndex, err = ioutil.ReadFile("assets/fdsn-ws-dataselect.html") + fdsnDataselectIndex, err = os.ReadFile("assets/fdsn-ws-dataselect.html") if err != nil { log.Printf("error reading assets/fdsn-ws-dataselect.html: %s", err.Error()) } diff --git a/cmd/fdsn-ws/fdsn_event.go b/cmd/fdsn-ws/fdsn_event.go index bc173be5..19bbcbde 100644 --- a/cmd/fdsn-ws/fdsn_event.go +++ b/cmd/fdsn-ws/fdsn_event.go @@ -5,7 +5,6 @@ import ( "database/sql" "errors" "fmt" - "io/ioutil" "log" "math" "net/http" @@ -110,7 +109,7 @@ func init() { } fdsnEventWadlFile = b.Bytes() - fdsnEventIndex, err = ioutil.ReadFile("assets/fdsn-ws-event.html") + fdsnEventIndex, err = os.ReadFile("assets/fdsn-ws-event.html") if err != nil { log.Printf("error reading assets/fdsn-ws-event.html: %s", err.Error()) } @@ -119,9 +118,10 @@ func init() { /* parses the time in text as per the FDSN spec. Pads text for parsing with time.RFC3339Nano. Accepted formats are (UTC): - YYYY-MM-DDTHH:MM:SS.ssssss - YYYY-MM-DDTHH:MM:SS - YYYY-MM-DD + + YYYY-MM-DDTHH:MM:SS.ssssss + YYYY-MM-DDTHH:MM:SS + YYYY-MM-DD Implements the encoding.TextUnmarshaler interface. */ diff --git a/cmd/fdsn-ws/fdsn_station.go b/cmd/fdsn-ws/fdsn_station.go index eee76ce4..a86d3869 100644 --- a/cmd/fdsn-ws/fdsn_station.go +++ b/cmd/fdsn-ws/fdsn_station.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "math" "net/http" @@ -127,7 +126,7 @@ func init() { } fdsnStationWadlFile = b.Bytes() - fdsnStationIndex, err = ioutil.ReadFile("assets/fdsn-ws-station.html") + fdsnStationIndex, err = os.ReadFile("assets/fdsn-ws-station.html") if err != nil { log.Printf("error reading assets/fdsn-ws-station.html: %s", err.Error()) } @@ -482,7 +481,7 @@ func fdsnStationV1Handler(r *http.Request, h http.Header, b *bytes.Buffer) error } params = []fdsnStationV1Search{p} case "POST": - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { return fdsnError{StatusError: weft.StatusError{Code: http.StatusBadRequest, Err: err}, timestamp: tm, url: r.URL.String()} } diff --git a/cmd/fdsn-ws/server_test.go b/cmd/fdsn-ws/server_test.go index 2ffbd7d1..aa0aac3c 100644 --- a/cmd/fdsn-ws/server_test.go +++ b/cmd/fdsn-ws/server_test.go @@ -2,7 +2,7 @@ package main import ( "database/sql" - "io/ioutil" + "io" "log" "net/http/httptest" "os" @@ -68,7 +68,7 @@ func setup(t *testing.T) { // Silence the logging unless running with // go test -v if !testing.Verbose() { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) } }