Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend table request/response #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
)
23 changes: 21 additions & 2 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
12 changes: 12 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -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