Skip to content

Commit

Permalink
fix lint errors: remove ioutil references and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmach committed Jan 8, 2024
1 parent b3aa927 commit f9fed71
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ var c = jsoniter.Config{
MarshalFloatWith6Digits: true,
}.Froze()

osmm.CustomJSONMarshaler = c
osm.CustomJSONMarshaler = c
osm.CustomJSONUnmarshaler = c
```

Expand Down
2 changes: 1 addition & 1 deletion annotate/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func wayCentroid(w *osm.Way) orb.Point {
return point
}

// orientation will annotate the the orientation of multipolygon relation members.
// orientation will annotate the orientation of multipolygon relation members.
// This makes it possible to reconstruct relations with partial data in the right direction.
// Return value indicates if the result is 'tainted', e.g. not all way members were present.
func orientation(members osm.Members, ways map[osm.WayID]*osm.Way, at time.Time) bool {
Expand Down
3 changes: 1 addition & 2 deletions annotate/way_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/xml"
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -132,7 +131,7 @@ func BenchmarkWays(b *testing.B) {
}

func loadTestdata(tb testing.TB, filename string) *osm.OSM {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
tb.Fatalf("unable to open file: %v", err)
}
Expand Down
20 changes: 12 additions & 8 deletions change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"encoding/xml"
"io/ioutil"
"os"
"testing"
)

Expand Down Expand Up @@ -237,11 +237,13 @@ func TestChange_HistoryDatasource(t *testing.T) {
}

func BenchmarkChange_MarshalXML(b *testing.B) {
filename := "testdata/changeset_38162206.osc"
data := readFile(b, filename)
data, err := os.ReadFile("testdata/changeset_38162206.osc")
if err != nil {
b.Fatalf("unable to read file: %v", err)
}

c := &Change{}
err := xml.Unmarshal(data, c)
err = xml.Unmarshal(data, c)
if err != nil {
b.Fatalf("unable to unmarshal: %v", err)
}
Expand Down Expand Up @@ -270,7 +272,7 @@ func BenchmarkChange_MarshalXML(b *testing.B) {
// }

func BenchmarkChange_MarshalJSON(b *testing.B) {
data, err := ioutil.ReadFile("testdata/minute_871.osc")
data, err := os.ReadFile("testdata/minute_871.osc")
if err != nil {
b.Fatalf("could not read file: %v", err)
}
Expand All @@ -292,7 +294,7 @@ func BenchmarkChange_MarshalJSON(b *testing.B) {
}

func BenchmarkChange_UnmarshalJSON(b *testing.B) {
data, err := ioutil.ReadFile("testdata/minute_871.osc")
data, err := os.ReadFile("testdata/minute_871.osc")
if err != nil {
b.Fatalf("could not read file: %v", err)
}
Expand Down Expand Up @@ -320,8 +322,10 @@ func BenchmarkChange_UnmarshalJSON(b *testing.B) {
}

func BenchmarkChangeset_UnmarshalXML(b *testing.B) {
filename := "testdata/changeset_38162206.osc"
data := readFile(b, filename)
data, err := os.ReadFile("testdata/changeset_38162206.osc")
if err != nil {
b.Fatalf("unable to read file: %v", err)
}

b.ReportAllocs()
b.ResetTimer()
Expand Down
20 changes: 15 additions & 5 deletions diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package osm

import (
"encoding/xml"
"os"
"reflect"
"testing"
)
Expand Down Expand Up @@ -72,10 +73,13 @@ func TestDiff_MarshalXML(t *testing.T) {
}

func TestDiff(t *testing.T) {
data := readFile(t, "testdata/annotated_diff.xml")
data, err := os.ReadFile("testdata/annotated_diff.xml")
if err != nil {
t.Fatalf("unable to read file: %v", err)
}

diff := &Diff{}
err := xml.Unmarshal(data, &diff)
err = xml.Unmarshal(data, &diff)
if err != nil {
t.Errorf("unable to unmarshal: %v", err)
}
Expand Down Expand Up @@ -137,10 +141,13 @@ func TestDiff(t *testing.T) {
}

func BenchmarkDiff_Marshal(b *testing.B) {
data := readFile(b, "testdata/annotated_diff.xml")
data, err := os.ReadFile("testdata/annotated_diff.xml")
if err != nil {
b.Fatalf("unable to read file: %v", err)
}

diff := &Diff{}
err := xml.Unmarshal(data, &diff)
err = xml.Unmarshal(data, &diff)
if err != nil {
b.Fatalf("unmarshal error: %v", err)
}
Expand All @@ -156,7 +163,10 @@ func BenchmarkDiff_Marshal(b *testing.B) {
}

func BenchmarkDiff_Unmarshal(b *testing.B) {
data := readFile(b, "testdata/annotated_diff.xml")
data, err := os.ReadFile("testdata/annotated_diff.xml")
if err != nil {
b.Fatalf("unable to read file: %v", err)
}

b.ReportAllocs()
b.ResetTimer()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/paulmach/osm

go 1.13
go 1.16

require (
github.com/datadog/czlib v0.0.0-20160811164712-4bc9a24e37f2
Expand Down
17 changes: 0 additions & 17 deletions osm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"io"
"os"
"reflect"
"testing"
)
Expand Down Expand Up @@ -301,18 +299,3 @@ func TestOSM_MarshalXML(t *testing.T) {
t.Errorf("incorrect marshal, got: %s", string(data))
}
}

func readFile(t testing.TB, filename string) []byte {
f, err := os.Open(filename)
if err != nil {
t.Fatalf("unable to open %s: %v", filename, err)
}
defer f.Close()

data, err := io.ReadAll(f)
if err != nil {
t.Fatalf("unable to read file %s: %v", filename, err)
}

return data
}
4 changes: 2 additions & 2 deletions osmgeojson/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package osmgeojson

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

"github.com/paulmach/osm"
Expand Down Expand Up @@ -88,7 +88,7 @@ func BenchmarkConvert_NoIDsMetaMembership(b *testing.B) {
}

func parseFile(t testing.TB, filename string) *osm.OSM {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
t.Fatalf("could not read file: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion osmgeojson/build_polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (ctx *context) buildPolygon(relation *osm.Relation) *geojson.Feature {
}

if len(ls) == 0 {
// we have the way but none the the node members
// we have the way but none of the node members
continue
}

Expand Down
2 changes: 1 addition & 1 deletion osmgeojson/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ type rawFC struct {
func jsonLoop(t *testing.T, fc *geojson.FeatureCollection) *rawFC {
data, err := json.Marshal(fc)
if err != nil {
t.Fatalf("unabled to marshal fc: %v", err)
t.Fatalf("unable to marshal fc: %v", err)
}

result := &rawFC{}
Expand Down
2 changes: 1 addition & 1 deletion osmgeojson/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NoMeta(yes bool) Option {
}
}

// NoRelationMembership will omit the the list of relations
// NoRelationMembership will omit the list of relations
// an element is a member of from the output geojson features.
func NoRelationMembership(yes bool) Option {
return func(ctx *context) error {
Expand Down
6 changes: 5 additions & 1 deletion relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"os"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -199,7 +200,10 @@ func TestRelation_MarshalXML(t *testing.T) {
}

// blanket xml test
data = readFile(t, "testdata/relation-updates.osm")
data, err = os.ReadFile("testdata/relation-updates.osm")
if err != nil {
t.Fatalf("could not read file: %v", err)
}

osm := &OSM{}
err = xml.Unmarshal(data, &osm)
Expand Down
3 changes: 1 addition & 2 deletions replication/changesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"

Expand Down Expand Up @@ -88,7 +87,7 @@ func (ds *Datasource) fetchChangesetState(ctx context.Context, n ChangesetSeqNum
}
}

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions replication/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"encoding/xml"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -219,7 +219,7 @@ func (ds *Datasource) fetchState(ctx context.Context, n SeqNum) (*State, error)
}
}

data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion way_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"os"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -284,7 +285,10 @@ func TestWay_MarshalXML(t *testing.T) {
}

// blanket xml test
data = readFile(t, "testdata/way-updates.osm")
data, err = os.ReadFile("testdata/way-updates.osm")
if err != nil {
t.Fatalf("unable to read file: %v", err)
}

osm := &OSM{}
err = xml.Unmarshal(data, &osm)
Expand Down

0 comments on commit f9fed71

Please sign in to comment.