servicediscovery

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//DefaultTTL = 5 * time.Minute
	DefaultTTL = 30 * time.Second
)
View Source
var ErrNoEndpoints = errors.New("no endpoints available")

ErrNoEndpoints is returned when no qualifying endpoints are available.

Functions

This section is empty.

Types

type Cache added in v1.6.6

type Cache interface {
	GetService(serviceName string) (*Service, error)
	// stop the cache of watcher
	Stop()
}

func NewCache added in v1.6.6

func NewCache(r IServiceDiscoveryClient, options *CacheOptions) Cache

type CacheOptions added in v1.6.6

type CacheOptions struct {
	// TTL is the cache TTL
	TTL time.Duration
}

type DefaultServiceInstance

type DefaultServiceInstance struct {
	Id          string
	ServiceName string
	Host        string
	Port        uint64
	ClusterName string
	GroupName   string
	Tags        []string
	Enable      bool
	Healthy     bool
	Weight      float64
	Metadata    map[string]string
}

DefaultServiceInstance the default implementation of ServiceInstance or change the ServiceInstance to be struct???

func (*DefaultServiceInstance) GetClusterName

func (d *DefaultServiceInstance) GetClusterName() string

func (*DefaultServiceInstance) GetGroupName

func (d *DefaultServiceInstance) GetGroupName() string

func (*DefaultServiceInstance) GetHost

func (d *DefaultServiceInstance) GetHost() string

GetHost will return the hostname

func (*DefaultServiceInstance) GetId

func (d *DefaultServiceInstance) GetId() string

GetId will return this instance's id. It should be unique.

func (*DefaultServiceInstance) GetMetadata

func (d *DefaultServiceInstance) GetMetadata() map[string]string

GetMetadata will return the metadata, it will never return nil

func (*DefaultServiceInstance) GetPort

func (d *DefaultServiceInstance) GetPort() uint64

GetPort will return the port.

func (*DefaultServiceInstance) GetServiceName

func (d *DefaultServiceInstance) GetServiceName() string

GetServiceName will return the serviceName

func (*DefaultServiceInstance) GetTags

func (d *DefaultServiceInstance) GetTags() []string

func (*DefaultServiceInstance) GetWeight

func (d *DefaultServiceInstance) GetWeight() float64

func (*DefaultServiceInstance) IsEnable

func (d *DefaultServiceInstance) IsEnable() bool

IsEnable will return the enable status of this instance

func (*DefaultServiceInstance) IsHealthy

func (d *DefaultServiceInstance) IsHealthy() bool

IsHealthy will return the value represent the instance whether healthy or not

type Event added in v1.6.6

type Event struct {
	// Id is registry id
	Id string
	// Type defines type of event
	Type EventType
	// Timestamp is event timestamp
	Timestamp time.Time
	// Service is registry service
	Service *Service
}

Event is registry event

type EventType added in v1.6.6

type EventType int

EventType defines registry event type

const (
	// Create is emitted when a new service is registered
	Create EventType = iota
	// Delete is emitted when an existing service is unregsitered
	Delete
	// Update is emitted when an existing service is updated
	Update
)

func (EventType) String added in v1.6.6

func (t EventType) String() string

String returns human readable event type

type ISelector added in v1.6.7

type ISelector interface {
	Select(serviceName string) (ServiceInstance, error)
}

type IServiceDiscovery

type IServiceDiscovery interface {
	GetName() string
	Register() error
	Update() error
	Unregister() error
	GetHealthyInstances(serviceName string) []ServiceInstance
	GetAllInstances(serviceName string) []ServiceInstance
	Destroy() error
	Watch(opts ...WatchOption) (Watcher, error)
	GetAllServices() ([]*Service, error)
}

type IServiceDiscoveryClient added in v1.6.6

type IServiceDiscoveryClient interface {
	GetAllServices() ([]*Service, error)
	GetAllServiceNames() ([]string, error)
	GetAllInstances(serviceName string) []ServiceInstance
	Watch(opts ...WatchOption) (Watcher, error)
	GetService(name string) (*Service, error)
}

type Next added in v1.6.6

type Next func() (ServiceInstance, error)

type Option added in v1.6.6

type Option func(o *CacheOptions)

type Result added in v1.6.6

type Result struct {
	Action  string
	Service *Service
}

type Selector added in v1.6.6

type Selector struct {
	DiscoveryCache Cache    //service discovery cache
	Strategy       Strategy //load balancing strategy
}

func NewSelector added in v1.6.7

func NewSelector(discoveryCache Cache, strategy Strategy) *Selector

func (*Selector) Select added in v1.6.6

func (s *Selector) Select(serviceName string) (ServiceInstance, error)

will set strategy and cache options Selector( strategy , cache ).Select(serviceName).(ServiceInstance)

type Service added in v1.6.6

type Service struct {
	Name     string            `json:"name"`
	Version  string            `json:"version"`
	Metadata map[string]string `json:"metadata"`
	Nodes    []ServiceInstance `json:"nodes"`
}

func Copy added in v1.6.6

func Copy(current []*Service) []*Service

Copy makes a copy of services

func CopyService added in v1.6.6

func CopyService(service *Service) *Service

CopyService make a copy of service

type ServiceInstance

type ServiceInstance interface {

	// GetId will return this instance's id. It should be unique.
	GetId() string

	// GetServiceName will return the serviceName
	GetServiceName() string

	// GetHost will return the hostname
	GetHost() string

	// GetPort will return the port.
	GetPort() uint64

	GetWeight() float64

	GetTags() []string

	GetClusterName() string

	GetGroupName() string

	// IsEnable will return the enable status of this instance
	IsEnable() bool

	// IsHealthy will return the value represent the instance whether healthy or not
	IsHealthy() bool

	// GetMetadata will return the metadata
	GetMetadata() map[string]string
}

ServiceInstance is the model class of an instance of a service, which is used for service registration and discovery.

type Strategy added in v1.6.6

type Strategy interface {
	//Next(serviceName string) (ServiceInstance, error)
	Next(instanceList []ServiceInstance) (ServiceInstance, error)
}

Balancer yields endpoints according to some heuristic.

type UriEntry added in v1.6.6

type UriEntry struct {
	Protocol string
	Host     string
	Port     string
	Endpoint string
}

type UriParser added in v1.6.6

type UriParser struct {
	// contains filtered or unexported fields
}

func NewUriParser added in v1.6.6

func NewUriParser(uri string) *UriParser

func (*UriParser) Generate added in v1.6.6

func (parser *UriParser) Generate(instanceHosting string) string

func (*UriParser) GetUriEntry added in v1.6.6

func (parser *UriParser) GetUriEntry() *UriEntry

type WatchOption added in v1.6.6

type WatchOption func(*WatchOptions)

type WatchOptions added in v1.6.6

type WatchOptions struct {
	// Specify a service to watch
	// If blank, the watch is for all services
	Service string
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Watcher added in v1.6.6

type Watcher interface {
	// Next is a blocking call
	Next() (*Result, error)
	Stop()
}

Jump to

Keyboard shortcuts

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