Documentation ¶
Overview ¶
Package discovery defines interfaces for service discovery. Developers that are willing to customize service discovery should implement their own Resolver and supply it with the option WithResolver at client's creation.
Index ¶
- Constants
- type Change
- type Instance
- type Resolver
- type Result
- type SynthesizedResolver
- func (sr SynthesizedResolver) Diff(key string, prev, next Result) (Change, bool)
- func (sr SynthesizedResolver) Name() string
- func (sr SynthesizedResolver) Resolve(ctx context.Context, key string) (Result, error)
- func (sr SynthesizedResolver) Target(ctx context.Context, target rpcinfo.EndpointInfo) string
Constants ¶
const ( ChangeEventName = "discovery_change" DeleteEventName = "discovery_delete" )
Predefined discovery event names.
const DefaultWeight = 10
DefaultWeight is the default weight for an instance.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
Change contains the difference between the current discovery result and the previous one. It is designed for providing detail information when dispatching an event for service discovery result change. Since the loadbalancer may rely on caching the result of resolver to improve performance, the resolver implementation should dispatch an event when result changes.
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 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 rpcinfo.EndpointInfo) (description string) // Resolve returns a list of instances for the given description of a target. Resolve(ctx context.Context, desc string) (Result, error) // Diff computes the difference between two results. // When `next` is cacheable, the Change should be cacheable, too. And the `Result` field's CacheKey in // the return value should be set with the given cacheKey. Diff(cacheKey string, prev, next Result) (Change, bool) // Name returns the name of the resolver. Name() string }
Resolver resolves the target endpoint into a list of Instance.
type Result ¶
Result contains the result of service discovery process. Cacheable tells whether the instance list can/should be cached. When Cacheable is true, CacheKey can be used to map the instance list in cache.
type SynthesizedResolver ¶
type SynthesizedResolver struct { TargetFunc func(ctx context.Context, target rpcinfo.EndpointInfo) string ResolveFunc func(ctx context.Context, key string) (Result, error) DiffFunc func(key string, prev, next Result) (Change, bool) NameFunc func() string }
SynthesizedResolver synthesizes a Resolver using a resolve function.
func (SynthesizedResolver) Diff ¶
func (sr SynthesizedResolver) Diff(key string, prev, next Result) (Change, bool)
Diff implements the Resolver interface.
func (SynthesizedResolver) Name ¶
func (sr SynthesizedResolver) Name() string
Name implements the Resolver interface
func (SynthesizedResolver) Target ¶
func (sr SynthesizedResolver) Target(ctx context.Context, target rpcinfo.EndpointInfo) string
Target implements the Resolver interface.