Skip to content

Commit

Permalink
fix: remove usage of deprecated package ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumNZ committed Jan 12, 2024
1 parent 5518adc commit 13f1d73
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
9 changes: 5 additions & 4 deletions cmd/fdsn-quake-consumer/sc3ml_backload_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions cmd/fdsn-quake-consumer/sc3ml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"database/sql"
"io/ioutil"
"io"
"os"
"reflect"
"runtime"
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/fdsn-ws-nrt/fdsn_dataselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/fdsn-ws-nrt/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/fdsn-ws/fdsn_dataselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -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())
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/fdsn-ws/fdsn_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"database/sql"
"errors"
"fmt"
"io/ioutil"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -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())
}
Expand All @@ -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.
*/
Expand Down
5 changes: 2 additions & 3 deletions cmd/fdsn-ws/fdsn_station.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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()}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/fdsn-ws/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"database/sql"
"io/ioutil"
"io"
"log"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 13f1d73

Please sign in to comment.