registry

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package registry provides the main glue between services

It wraps micro registry (running services declared to the discovery server) into a more generic registry where all actual plugins are self-declared.

Package registry provides the main glue between services

It wraps micro registry (running services declared to the discovery server) into a more generic registry where all actual plugins are self-declared.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default registry
	Default = NewRegistry()
)

Functions

func GetClient

func GetClient(name string) (string, client.Client)

GetClient returns the default client for the service name

func GetPeers added in v1.2.2

func GetPeers() map[string]*Peer

func Init

func Init(opts ...Option)

Init the default registry

Types

type Nodes

type Nodes []*registry.Node

Nodes wraps an array of registry nodes

func (Nodes) StringArray

func (n Nodes) StringArray() []string

StringArray representation of the registry nodes

type Option

type Option func(*Options)

Option is a gateway to setting Options to the Registry

func Name

func Name(n string) Option

Name links a name as a registry option

func PollInterval

func PollInterval(interval time.Duration) Option

PollInterval defines an interval option to a watcher

type Options

type Options struct {
	Name         string
	PollInterval time.Duration

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

Options defines options to the Registry itself

type Peer added in v1.2.2

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

func NewPeer added in v1.2.2

func NewPeer(address string) *Peer

func (*Peer) Add added in v1.2.2

func (p *Peer) Add(c *registry.Service, id string)

func (*Peer) Delete added in v1.2.2

func (p *Peer) Delete(c *registry.Service, id string)

func (*Peer) GetServices added in v1.2.2

func (p *Peer) GetServices(name ...string) []*registry.Service

type RegisterOption

type RegisterOption func(*RegisterOptions)

RegisterOption is a gateway to setting RegisterOptions to a Registry Entry

func RegisterDependencies

func RegisterDependencies(d ...string) RegisterOption

RegisterDependencies adds dependencies between services to the registry entry

func RegisterFlags

func RegisterFlags(f ...*pflag.Flag) RegisterOption

RegisterFlags adds flags to the registry entry service

type RegisterOptions

type RegisterOptions struct {
	Dependencies []string
	Flags        []*pflag.Flag

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

RegisterOptions defines different options for the Register entry

type Registry

type Registry interface {
	Init(...Option)
	Register(Service, ...RegisterOption) error
	Deregister(Service) error
	GetService(string) ([]Service, error)
	GetServicesByName(string) []Service
	GetPeers() map[string]*Peer
	ListServices(withExcluded ...bool) ([]Service, error)
	ListRunningServices() ([]Service, error)
	ListServicesWithMicroMeta(string, ...string) ([]Service, error)
	SetServiceStopped(string) error
	Filter(func(Service) bool) error
	Watch() (Watcher, error)
	String() string
	Options() Options

	BeforeInit() error
	AfterInit() error
}

Registry provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}

func NewRegistry

func NewRegistry(opts ...Option) Registry

NewRegistry provides a new registry object

type Result

type Result struct {
	Action  string
	Service Service
}

Result of a Watch Message

type Service

type Service interface {
	Start()
	Stop()

	IsRunning() bool
	IsExcluded() bool
	SetExcluded(ex bool)
	Check(context.Context) error

	Name() string
	Address() string
	Regexp() *regexp.Regexp
	Version() string
	Description() string
	Tags() []string
	GetDependencies() []Service
	AddDependency(string)
	SetRunningNodes([]*registry.Node)
	RunningNodes() []*registry.Node

	IsGeneric() bool
	IsGRPC() bool
	IsREST() bool

	RequiresFork() bool
	ForkStart()
	MustBeUnique() bool
	AutoStart() bool

	MatchesRegexp(string) bool

	BeforeInit() error
	AfterInit() error
}

Service defines the primary functions a service must be able to answer to for the registry

func ListRunningServices

func ListRunningServices() ([]Service, error)

ListRunningServices returns the list of services that are started in the system

func ListServices

func ListServices(withExcluded ...bool) ([]Service, error)

ListServices returns the list of services that are started in the system

func ListServicesWithMicroMeta

func ListServicesWithMicroMeta(metaName string, metaValue ...string) ([]Service, error)

ListServicesWithMicroMeta lists the services that have a specific meta name and value associated

type Watcher

type Watcher interface {
	Next() (*Result, error)
	Stop()
}

Watcher defines the functions used to watch the registry

func Watch

func Watch() (Watcher, error)

Watch triggers a watch of the default registry

Jump to

Keyboard shortcuts

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