Created
January 22, 2020 06:36
-
-
Save hbd/211c554542cccac5016074a8e293a5f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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