Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Balancer ¶
type Balancer interface {
// Select returns a *api.ServiceEntry describing the selected target.
// If Select failed to provide a viable target, it should return a non-nil error.
// Important: Select must be non-blocking!
Select() (*api.ServiceEntry, error)
// UpdateTargets will be called periodically to refresh the Balancer's targets list from which the Balancer is allowed to select
UpdateTargets(targets []*api.ServiceEntry)
}
Balancer interface provides methods for selecting a target and updating its state
type LoadBalancedTransport ¶
type LoadBalancedTransport struct {
// contains filtered or unexported fields
}
func NewLoadBalancedTransport ¶
func NewLoadBalancedTransport(conf TransportConfig) (*LoadBalancedTransport, error)
type Resolver ¶
type Resolver interface {
// Resolve should return a ServiceAddress, or a non-nil error if resolution failed
Resolve(context.Context) (ServiceAddress, error)
// ServiceName should return the name of the service the resolver is providing targets for
// Target resolution will be skipped for hosts that do not match the name returned by ServiceName
ServiceName() string
}
type ResolverConfig ¶
type ResolverConfig struct {
// A function that will be used for logging.
// Optional
// Default: log.Printf
Log LogFn
// The Service Spec the resolver will handle
// Mandatory
ServiceSpec ServiceSpec
// The Balancer that will be used to select targets
// Optional
// Default: RoundRobinLoadBalancer
Balancer Balancer
// The consul client
// Mandatory
Client *api.Client
// The consul query options configuration
// Optional
Query *api.QueryOptions
// A list of datacenters to query, ordered by priority.
// Optional. Will use only the local DC if not provided.
FallbackDatacenters []string
}
type ServiceAddress ¶
type ServiceProvider ¶
type ServiceProvider interface {
ServiceMultipleTags(service string, tags []string, passingOnly bool, q *api.QueryOptions) ([]*api.ServiceEntry, *api.QueryMeta, error)
}
ServiceProvider provides a method for obtaining a list of *api.ServiceEntry entities from Consul
type ServiceResolver ¶
type ServiceResolver struct {
// contains filtered or unexported fields
}
func NewConsulResolver ¶
func NewConsulResolver(ctx context.Context, conf ResolverConfig) (*ServiceResolver, error)
NewConsulResolver creates a new Consul Resolver ctx - a context used for graceful termination of the consul-watcher go routine. Note that canceling the context will render the resolver stale, and any attempt to use it will immediately return an error conf - the resolver's config
func (*ServiceResolver) Resolve ¶
func (r *ServiceResolver) Resolve(ctx context.Context) (ServiceAddress, error)
Resolve returns a single ServiceAddress instance of the resolved target
func (*ServiceResolver) ServiceName ¶
func (r *ServiceResolver) ServiceName() string
ServiceName returns the service name that the resolver is looking up
type ServiceSpec ¶
type ServiceSpec struct {
// The name of the service in Consul.
// Mandatory
ServiceName string
// The port to use, if different from the `Service.Port` in Consul
// If set to a value other than 0, this will override the service port discovered in Consul.
// Optional
// Default: 0
ServicePort int
// Filter service instances by Consul tags.
// Optional
// Default: nil
Tags []string
// Filter service instances by Health status.
// Optional
// Default: false (only healthy endpoints are used)
IncludeUnhealthy bool
}
type TransportConfig ¶
type TransportConfig struct {
// A function that will be used for logging.
// Optional
// Default: log.Printf
Log LogFn
// The resolvers to be used for address resolution.
// Multiple resolvers are supported, and will be looked up by the `ServiceName`
// Mandatory
Resolvers []Resolver
// If true, the transport will fallback to net/Resolver on resolver error
// Optional
// Default: false
NetResolverFallback bool
// A base transport to be used for the underlying request handling.
// Optional
// Default: http.DefaultTransport
Base http.RoundTripper
}
Click to show internal directories.
Click to hide internal directories.