From 5e711f929f5d47f026e5d73204b7efe001ff9781 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 21 Nov 2020 23:56:08 +0200 Subject: [PATCH] extend table request/response --- go.mod | 4 +++- table.go | 23 +++++++++++++++++++++-- table_test.go | 10 +++++++--- types.go | 12 ++++++++++++ vendor/modules.txt | 3 +++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 74470fa..2438826 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,9 @@ module github.com/gojuno/go.osrm +go 1.15 + require ( github.com/paulmach/go.geo v0.0.0-20180829195134-22b514266d33 - github.com/paulmach/go.geojson v1.4.0 // indirect + github.com/paulmach/go.geojson v1.4.0 github.com/stretchr/testify v1.3.0 ) diff --git a/table.go b/table.go index a539131..908ac88 100644 --- a/table.go +++ b/table.go @@ -5,12 +5,20 @@ type TableRequest struct { Profile string Coordinates Geometry Sources, Destinations []int + Annotations Annotations + FallbackSpeed float64 + FallbackCoordinate FallbackCoordinate + ScaleFactor float64 } // TableResponse resresents a response from the table method type TableResponse struct { ResponseStatus - Durations [][]float32 `json:"durations"` + Durations [][]float32 `json:"durations"` + Distances [][]float32 `json:"distances"` + Sources []Waypoint `json:"sources"` + Destinations []Waypoint `json:"destinations"` + FallbackSpeedCells [][]bool `json:"fallback_speed_cells"` } func (r TableRequest) request() *request { @@ -21,7 +29,18 @@ func (r TableRequest) request() *request { if len(r.Destinations) > 0 { opts.addInt("destinations", r.Destinations...) } - + if len(r.Annotations) > 0 { + opts.setStringer("annotations", r.Annotations) + } + if r.FallbackSpeed > 0 { + opts.addFloat("fallback_speed", r.FallbackSpeed) + } + if len(r.FallbackCoordinate) > 0 { + opts.setStringer("fallback_coordinate", r.FallbackCoordinate) + } + if r.ScaleFactor > 0 { + opts.addFloat("scale_factor", r.ScaleFactor) + } return &request{ profile: r.Profile, coords: r.Coordinates, diff --git a/table_test.go b/table_test.go index cf8a55f..d4574bc 100644 --- a/table_test.go +++ b/table_test.go @@ -13,8 +13,12 @@ func TestEmptyTableRequestOptions(t *testing.T) { func TestNotEmptyTableRequestOptions(t *testing.T) { req := TableRequest{ - Sources: []int{0, 1, 2}, - Destinations: []int{1, 3}, + Sources: []int{0, 1, 2}, + Destinations: []int{1, 3}, + Annotations: AnnotationsDuration, + FallbackSpeed: 45, + FallbackCoordinate: FallbackCoordinateSnapped, + ScaleFactor: 1.052, } - assert.Equal(t, "destinations=1;3&sources=0;1;2", req.request().options.encode()) + assert.Equal(t, "annotations=duration&destinations=1;3&fallback_coordinate=snapped&fallback_speed=45&scale_factor=1.052&sources=0;1;2", req.request().options.encode()) } diff --git a/types.go b/types.go index 8f5a559..82eb45c 100644 --- a/types.go +++ b/types.go @@ -159,6 +159,18 @@ func (o Overview) String() string { return string(o) } +type FallbackCoordinate string + +const ( + FallbackCoordinateDefault FallbackCoordinate = "input" + FallbackCoordinateInput FallbackCoordinate = "input" + FallbackCoordinateSnapped FallbackCoordinate = "snapped" +) + +func (f FallbackCoordinate) String() string { + return string(f) +} + // ContinueStraight represents continue_straight OSRM routing parameter type ContinueStraight string diff --git a/vendor/modules.txt b/vendor/modules.txt index 1ccfc62..d4483dd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,11 +1,14 @@ # github.com/davecgh/go-spew v1.1.0 github.com/davecgh/go-spew/spew # github.com/paulmach/go.geo v0.0.0-20180829195134-22b514266d33 +## explicit github.com/paulmach/go.geo # github.com/paulmach/go.geojson v1.4.0 +## explicit github.com/paulmach/go.geojson # github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib/difflib # github.com/stretchr/testify v1.3.0 +## explicit github.com/stretchr/testify/assert github.com/stretchr/testify/require