add eta method to routing service

This commit is contained in:
Asim Aslam
2021-04-26 16:03:21 +01:00
parent 334336ca6f
commit 4390fdad76
5 changed files with 318 additions and 73 deletions

View File

@@ -42,7 +42,10 @@ func NewRoutingEndpoints() []*api.Endpoint {
// Client API for Routing service
type RoutingService interface {
// Route returns a gps route from origin to destination based on lat/lng
Route(ctx context.Context, in *RouteRequest, opts ...client.CallOption) (*RouteResponse, error)
// ETA returns an estimated time of arrival for a route
ETA(ctx context.Context, in *ETARequest, opts ...client.CallOption) (*ETAResponse, error)
}
type routingService struct {
@@ -67,15 +70,29 @@ func (c *routingService) Route(ctx context.Context, in *RouteRequest, opts ...cl
return out, nil
}
func (c *routingService) ETA(ctx context.Context, in *ETARequest, opts ...client.CallOption) (*ETAResponse, error) {
req := c.c.NewRequest(c.name, "Routing.ETA", in)
out := new(ETAResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Routing service
type RoutingHandler interface {
// Route returns a gps route from origin to destination based on lat/lng
Route(context.Context, *RouteRequest, *RouteResponse) error
// ETA returns an estimated time of arrival for a route
ETA(context.Context, *ETARequest, *ETAResponse) error
}
func RegisterRoutingHandler(s server.Server, hdlr RoutingHandler, opts ...server.HandlerOption) error {
type routing interface {
Route(ctx context.Context, in *RouteRequest, out *RouteResponse) error
ETA(ctx context.Context, in *ETARequest, out *ETAResponse) error
}
type Routing struct {
routing
@@ -91,3 +108,7 @@ type routingHandler struct {
func (h *routingHandler) Route(ctx context.Context, in *RouteRequest, out *RouteResponse) error {
return h.RoutingHandler.Route(ctx, in, out)
}
func (h *routingHandler) ETA(ctx context.Context, in *ETARequest, out *ETAResponse) error {
return h.RoutingHandler.ETA(ctx, in, out)
}