diff --git a/README.md b/README.md index 9d65d09..594da6a 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ var c = jsoniter.Config{ MarshalFloatWith6Digits: true, }.Froze() -osmm.CustomJSONMarshaler = c +osm.CustomJSONMarshaler = c osm.CustomJSONUnmarshaler = c ``` diff --git a/annotate/geo.go b/annotate/geo.go index 91ba7ab..a17a3ba 100644 --- a/annotate/geo.go +++ b/annotate/geo.go @@ -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 { diff --git a/annotate/way_test.go b/annotate/way_test.go index 42d35ce..01bc933 100644 --- a/annotate/way_test.go +++ b/annotate/way_test.go @@ -4,7 +4,6 @@ import ( "context" "encoding/xml" "fmt" - "io/ioutil" "os" "reflect" "testing" @@ -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) } diff --git a/change_test.go b/change_test.go index 444d754..085f60a 100644 --- a/change_test.go +++ b/change_test.go @@ -5,7 +5,7 @@ import ( "context" "encoding/json" "encoding/xml" - "io/ioutil" + "os" "testing" ) @@ -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) } @@ -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) } @@ -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) } @@ -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() diff --git a/diff_test.go b/diff_test.go index 0955747..6ff329b 100644 --- a/diff_test.go +++ b/diff_test.go @@ -2,6 +2,7 @@ package osm import ( "encoding/xml" + "os" "reflect" "testing" ) @@ -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) } @@ -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) } @@ -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() diff --git a/go.mod b/go.mod index 5ea8c27..19eb1b3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/osm_test.go b/osm_test.go index a80c807..7f57c8a 100644 --- a/osm_test.go +++ b/osm_test.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/json" "encoding/xml" - "io" - "os" "reflect" "testing" ) @@ -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 -} diff --git a/osmgeojson/benchmarks_test.go b/osmgeojson/benchmarks_test.go index 4877187..3d25259 100644 --- a/osmgeojson/benchmarks_test.go +++ b/osmgeojson/benchmarks_test.go @@ -2,7 +2,7 @@ package osmgeojson import ( "encoding/xml" - "io/ioutil" + "os" "testing" "github.com/paulmach/osm" @@ -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) } diff --git a/osmgeojson/build_polygon.go b/osmgeojson/build_polygon.go index bc00284..e78c4d3 100644 --- a/osmgeojson/build_polygon.go +++ b/osmgeojson/build_polygon.go @@ -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 } diff --git a/osmgeojson/convert_test.go b/osmgeojson/convert_test.go index 3209d0e..3c59e83 100644 --- a/osmgeojson/convert_test.go +++ b/osmgeojson/convert_test.go @@ -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{} diff --git a/osmgeojson/options.go b/osmgeojson/options.go index dd8321d..ac838be 100644 --- a/osmgeojson/options.go +++ b/osmgeojson/options.go @@ -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 { diff --git a/relation_test.go b/relation_test.go index bb19e92..63b4b5e 100644 --- a/relation_test.go +++ b/relation_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "encoding/xml" + "os" "reflect" "testing" "time" @@ -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) diff --git a/replication/changesets.go b/replication/changesets.go index f149c8c..65eb273 100644 --- a/replication/changesets.go +++ b/replication/changesets.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/http" "strconv" @@ -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 } diff --git a/replication/interval.go b/replication/interval.go index 8c258bd..d322d85 100644 --- a/replication/interval.go +++ b/replication/interval.go @@ -6,7 +6,7 @@ import ( "context" "encoding/xml" "fmt" - "io/ioutil" + "io" "net/http" "strconv" "time" @@ -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 } diff --git a/way_test.go b/way_test.go index 59d7ab3..d669bbd 100644 --- a/way_test.go +++ b/way_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "encoding/xml" + "os" "reflect" "testing" "time" @@ -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)