Categorygithub.com/marcsantiago/api-router
modulepackage
1.0.2
Repository: https://github.com/marcsantiago/api-router.git
Documentation: pkg.go.dev

# README

api-router

Go

The pupose of this package is to pick the best API endpoint for reduced latency.

e.g API endpoint has 3 regional endpoints:

us-east-1 us-east-2 us-west-1

You have an app deployed on us-east-2 You'd want to use us-east-2, but you have to know that ahead of time. Or you select us-east-2, but that service is down at that region...so you'd want to gracefully fallback to us-east-1.. This package is designed to mediate which URI your app should call.

# Functions

NewLatencyRouter returns a fully initialized network based API router if the inputted client is nil, the default client will be used underneath, which has a 500ms timeout.

# Variables

ErrAtLeastOne at least one field of EndPoints needs to initialized.
ErrBadStatus notifies the user that the status code is not a 200.
ErrConnectionReset represents a connection was reset during a network call.
ErrFallbackUnset notifies that the fallback should be sent, even if it's a duplicative endpoint.
ErrMissingProtocol a protocol must be present with each endpoint.
ErrNoSuchHost the host could not be found on the endpoint.
ErrTimeout indicates a network timeout.

# Structs

EndPoints belonging the the API service that is being used.
Latency creates a router based on API latency, in order for endpoints to be checked PingInterval must be set, otherwise it will fallback to relying on AWS regional information if set and lastly to the fallback URL if none of the above is set.