Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoEndpoints is returned when you passed no endpoints to the Resolver. ErrNoEndpoints = errors.New("no endpoints specified") )
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶
type Endpoint struct { Addr string // e.g. 127.0.0.1:10000 CheckURL string // e.g. http://127.0.0.1:10000/healthz // contains filtered or unexported fields }
Endpoint is an endpoint that serves gRPC and responds to health checks on the CheckURL.
type Logger ¶
type Logger interface {
Printf(format string, values ...interface{})
}
Logger allows to pass an optional logger to the resolver.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver implements the gRPC Resolver interface using a simple health endpoint check on a list of clients initially passed to the resolver.
See the gRPC load balancing documentation for details about Balancer and Resolver: https://github.com/grpc/grpc/blob/master/doc/load-balancing.md.
func NewResolver ¶
func NewResolver(options ...ResolverOption) (*Resolver, error)
NewResolver initializes and returns a new Resolver.
It resolves addresses for gRPC connections to the given list of host:port endpoints. It runs HTTP-based health checks periodically to ensure that all endpoints are still reachable and healthy. If an endpoint does not respond in time, it is removed from the list of valid endpoints. Once it comes up again, it will be added to the list of healthy endpoints again, and traffic will be served to that endpoint again.
func (*Resolver) Next ¶
Next blocks until an update or error happens. It may return one or more updates. The first call will return the full set of instances available as NewResolver will look those up. Subsequent calls to Next() will block until the resolver finds any new or removed instance.
An error is returned if and only if the watcher cannot recover.
type ResolverOption ¶
ResolverOption is a callback for setting the options of the Resolver.
func SetCheckTimeout ¶
func SetCheckTimeout(timeout time.Duration) ResolverOption
SetCheckTimeout specifies the duration after which an endpoint is considered gone in a health check.
func SetEndpoints ¶
func SetEndpoints(endpoints ...Endpoint) ResolverOption
SetEndpoints specifies the endpoints for the resolver.
func SetLogger ¶
func SetLogger(logger Logger) ResolverOption
SetLogger allows to pass a logger for Resolver.
func SetUpdateInterval ¶
func SetUpdateInterval(interval time.Duration) ResolverOption
SetUpdateInterval specifies the interval in which to run health checks.