-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroute.go
More file actions
30 lines (22 loc) · 750 Bytes
/
route.go
File metadata and controls
30 lines (22 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package gosrm
import (
"context"
)
// routeServiceURL is the base path of OSRM route service.
const routeServiceURL string = "/route/v1"
// RouteResponse is the response of OSRM's route service.
type RouteResponse[T GeometryType] struct {
Response
Routes []RouteType[T] `json:"routes"`
Waypoints []Waypoint `json:"waypoints"`
}
// Route finds the fastest route between coordinates in the supplied order.
func Route[T GeometryType](ctx context.Context, osrm OSRMClient, req Request, opts ...Option) (*RouteResponse[T], error) {
u := req.buildURLPath(*osrm.baseURL, routeServiceURL)
osrm.applyOpts(u, opts)
var res RouteResponse[T]
if err := osrm.get(ctx, u.String(), &res); err != nil {
return nil, err
}
return &res, nil
}