{"modulePath":"github.com/vcabbage/kit","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lb\n\nPackage lb implements the client-side load balancer pattern. When combined with a service discovery system of record, it enables a more decentralized architecture, removing the need for separate load balancers like HAProxy.\n\n## Variables\n\n```go\nvar ErrNoEndpoints = errors.New(\"no endpoints available\")\n```\nErrNoEndpoints is returned when no qualifying endpoints are available.\n\n## Functions\n\n```go\nfunc Retry(max int, timeout time.Duration, b Balancer) endpoint.Endpoint\n```\nRetry wraps a service load balancer and returns an endpoint oriented load balancer for the specified service method. Requests to the endpoint will be automatically load balanced via the load balancer. Requests that return errors will be retried until they succeed, up to max times, or until the timeout is elapsed, whichever comes first.\n\n```go\nfunc RetryWithCallback(timeout time.Duration, b Balancer, cb Callback) endpoint.Endpoint\n```\nRetryWithCallback wraps a service load balancer and returns an endpoint oriented load balancer for the specified service method. Requests to the endpoint will be automatically load balanced via the load balancer. Requests that return errors will be retried until they succeed, up to max times, until the callback returns false, or until the timeout is elapsed, whichever comes first.\n\n## Types\n\n```go\ntype Balancer interface {\n\tEndpoint() (endpoint.Endpoint, error)\n}\n```\nBalancer yields endpoints according to some heuristic.\n\n```go\nfunc NewRandom(s sd.Endpointer, seed int64) Balancer\n```\nNewRandom returns a load balancer that selects services randomly.\n\n```go\nfunc NewRoundRobin(s sd.Endpointer) Balancer\n```\nNewRoundRobin returns a load balancer that returns services in sequence.\n\n```go\ntype Callback func(n int, received error) (keepTrying bool, replacement error)\n```\nCallback is a function that is given the current attempt count and the error received from the underlying endpoint. It should return whether the Retry function should continue trying to get a working endpoint, and a custom error if desired. The error message may be nil, but a true/false is always expected. In all cases, if the replacement error is supplied, the received error will be replaced in the calling context.\n\n```go\ntype RetryError struct {\n\tRawErrors []error // all errors encountered from endpoints directly\n\tFinal     error   // the final, terminating error\n}\n```\nRetryError is an error wrapper that is used by the retry mechanism. All errors returned by the retry mechanism via its endpoint will be RetryErrors.\n\n```go\nfunc (e RetryError) Error() string\n```\n\n","path":"github.com/vcabbage/kit/sd/lb","name":"lb","synopsis":"Package lb implements the client-side load balancer pattern.","isRedistributable":true}
