Skip to content

Instantly share code, notes, and snippets.

@hbd
Created January 22, 2020 06:36
Show Gist options
  • Save hbd/211c554542cccac5016074a8e293a5f8 to your computer and use it in GitHub Desktop.
Save hbd/211c554542cccac5016074a8e293a5f8 to your computer and use it in GitHub Desktop.
package location
type Client struct {
clients []locationiface.Client
}
func NewClient(clients ...locationiface.Client) *Client {
return &Client{clients: clients}
}
func (c *Client) DriveTime(ctx context.Context, locations ...Location) (float64, error) {
// Call external APIs.
for idx, c := range clients {
driveTime, err := c.DriveTime(ctx, locations...)
if err == nil {
return driveTime, nil
}
log.WithError(err).WithField("client_idx", idx).Error("Error retrieving driving distance.")
}
return 0, errors.New("failed to retrieve drive time from any client")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment