Documentation ¶
Index ¶
Constants ¶
const ( DefaultRefreshInterval = 5 * time.Second DefaultExpireInterval = 15 * time.Second )
Variables ¶
var DefaultLbOpts = Options{ RefreshInterval: DefaultRefreshInterval, ExpireInterval: DefaultExpireInterval, }
Functions ¶
func NewNetAddr ¶
NewNetAddr creates a new NetAddr object with the network and address provided.
Types ¶
type BalancerFactory ¶
type BalancerFactory struct {
// contains filtered or unexported fields
}
func NewBalancerFactory ¶
func NewBalancerFactory(config Config) *BalancerFactory
NewBalancerFactory get or create a balancer with given target. If it has the same key(resolver.Target(target)), we will cache and reuse the Balance.
func (*BalancerFactory) GetInstance ¶
type Config ¶
type Config struct { Resolver Resolver Balancer Loadbalancer LbOpts Options }
type Instance ¶
type Instance interface { Address() net.Addr Weight() int Tag(key string) (value string, exist bool) }
Instance contains information of an instance from the target service.
type Loadbalancer ¶
type Loadbalancer interface { // Pick is used to select an instance according to discovery result Pick(Result) Instance // Rebalance is used to refresh the cache of load balance's information Rebalance(Result) // Delete is used to delete the cache of load balance's information when it is expired Delete(string) // Name returns the name of the Loadbalancer. Name() string }
Loadbalancer picks instance for the given service discovery result.
func NewWeightedBalancer ¶
func NewWeightedBalancer() Loadbalancer
type NetAddr ¶
type NetAddr struct {
// contains filtered or unexported fields
}
NetAddr implements the net.Addr interface.
type Options ¶
type Options struct { // refresh discovery result timely RefreshInterval time.Duration // Balancer expire check interval // we need remove idle Balancers for resource saving ExpireInterval time.Duration }
Options for LoadBalance option
type Resolver ¶
type Resolver interface { // Target should return a description for the given target that is suitable for being a key for cache. Target(ctx context.Context, target *TargetInfo) string // Resolve returns a list of instances for the given description of a target. Resolve(ctx context.Context, desc string) (Result, error) // Name returns the name of the resolver. Name() string }
type Result ¶
Result contains the result of service discovery process. the instance list can/should be cached and CacheKey can be used to map the instance list in cache.
type SynthesizedResolver ¶
type SynthesizedResolver struct { TargetFunc func(ctx context.Context, target *TargetInfo) string ResolveFunc func(ctx context.Context, key string) (Result, error) NameFunc func() string }
SynthesizedResolver synthesizes a Resolver using a resolve function.
func (SynthesizedResolver) Name ¶
func (sr SynthesizedResolver) Name() string
Name implements the Resolver interface
func (SynthesizedResolver) Target ¶
func (sr SynthesizedResolver) Target(ctx context.Context, target *TargetInfo) string