discovery

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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.

func NewInstance

func NewInstance(network, address string, weight int, tags map[string]string) Instance

NewInstance creates an Instance using the given network, address and tags

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

type Result struct {
	CacheKey  string
	Instances []Instance
}

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) Resolve

func (sr SynthesizedResolver) Resolve(ctx context.Context, key string) (Result, error)

func (SynthesizedResolver) Target

func (sr SynthesizedResolver) Target(ctx context.Context, target *TargetInfo) string

type TargetInfo

type TargetInfo struct {
	Host string
	Tags map[string]string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL