Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInternalServerHTTPError = &JSONError{ Message: "Internal server error, please try again later.", Wrapped: errors.New("internal server error"), Status: http.StatusInternalServerError, }
ErrInternalServerHTTPError is JSONError implementation for http Internal server error.
var ErrInvalidCoordinatesFmt = errors.New("invalid coordinates format")
Functions ¶
func RoutesHandler ¶
func RoutesHandler(router Router) http.HandlerFunc
RoutesHandler is HTTP handler which return list of routes between source and each destination.
Source is provided with "src" single query parameter and destinations are provided with "dst" multiple query parameters.
Both source and destinations should implement following structure:
long,lat
Where long is longitude and lat is latitude.
Example source (or any destination) value:
13.388860,52.517037
Types ¶
type Coordinates ¶
type Coordinates struct { // Longitude is a geographic coordinate that specifies the // east-west position of a point on the Earth's surface. Longitude float64 `json:"long"` // Latitude is a geographic coordinate that specifies the // north-south position of a point on the Earth's surface. Latitude float64 `json:"lat"` }
Coordinates, composed from longitude and latitude, are the units that represent the coordinates at geographic coordinate system.
func CoordinatesFromString ¶
func CoordinatesFromString(s string) (*Coordinates, error)
CoordinatesFromString parses coordinates values from string representation of longitude and latitude.
func (Coordinates) String ¶
func (d Coordinates) String() string
String implements fmt.Stringer interface. It returns formal representation of Longitude and Latitude where both values are separated by comma and Longitude is the first one.
type JSONError ¶
type JSONError struct { // Wrapped error value. Wrapped error // Message is safe error message, that can be shown to the client. Message string // Status is http status header code. Status int }
JSONError is http JSON API error with http.Handler implementation.
type OSRMClient ¶
type OSRMClient struct { // ServiceURL is url of OSRM service. ServiceURL string // Client is HTTP client for OSRMClient API client used // for sending HTTP requests. Client *http.Client }
OSRMClient is HTTP API client for OSRM service.
func (*OSRMClient) Routes ¶
func (c *OSRMClient) Routes(ctx context.Context, req RoutesRequest) (*OSRMRouteResponse, error)
Routes finds the fastest route between coordinates in the supplied order.
See http://project-osrm.org/docs/v5.24.0/api/#route-service for more help.
type OSRMRoute ¶
type OSRMRoute struct { // Duration is the estimated travel time, in float // number of seconds. Duration float64 `json:"duration"` // Distance traveled by the route, in float meters. Distance float64 `json:"distance"` }
OSRMRoute represents a route through (potentially multiple) waypoints.
type OSRMRouteResponse ¶
type OSRMRouteResponse struct { // Code is "Ok" if the request was successful. Code string `json:"code"` // Routes is an array of Route objects, ordered by // descending recommendation rank. Routes []OSRMRoute `json:"routes"` }
OSRMRouteResponse of routes OSRM endpoint.
type Route ¶
type Route struct { // Destination holds coordinates for destination position. Destination Coordinates `json:"destination"` // Duration is the estimated travel time, in float // number of seconds. Duration float64 `json:"duration"` // Distance traveled by the route, in float meters. Distance float64 `json:"distance"` }
Route represents route's metadata for hypothetical source position.
type Router ¶
type Router interface { // Routes return a list of routes between source and each destination. Routes(ctx context.Context, src Coordinates, dst ...Coordinates) ([]Route, error) }
Router takes the source and a list of destinations and returns a list of routes between source and each destination.
type RoutesRequest ¶
type RoutesRequest struct { // Source is the beginning of the route. Source Coordinates // Destination is the end of the route. Destination Coordinates }
RoutesRequest holds arguments for Routes API call.
type RoutesSorter ¶
type RoutesSorter struct { // Wrapped router interface. Its returned value will be // sorted and returned further. Wrapped Router }
RoutesSorter is decorator which sorts routes returned by wrapped Router by the driving time and by the distance (if time is equal).
func (*RoutesSorter) Routes ¶
func (rs *RoutesSorter) Routes(ctx context.Context, src Coordinates, dst ...Coordinates) ([]Route, error)
Routes return a list of routes between source and each destination.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is main application interface. It exposes application's functionalities through HTTP protocol.
type Service ¶
type Service struct { // Client is HTTP OSRM API client. Client *OSRMClient }
Service is entry point for all high level operations related to purpose of the whole application, which is finding routes between source and multiple destinations.
func (*Service) Routes ¶
func (s *Service) Routes(ctx context.Context, src Coordinates, dst ...Coordinates) ([]Route, error)
Routes return a list of routes between source and each destination.