registry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: AGPL-3.0 Imports: 13 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.

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 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 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
	ListServices(withExcluded ...bool) ([]Service, error)
	ListRunningServices() ([]Service, error)
	ListServicesWithMicroMeta(string, ...string) ([]Service, 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
	Regexp() *regexp.Regexp
	Version() string
	Description() string
	Tags() []string
	GetDependencies() []Service
	AddDependency(string)
	SetRunningNodes([]*registry.Node)
	RunningNodes() []*registry.Node
	ExposedConfigs() *forms.Form

	IsGeneric() bool
	IsGRPC() bool
	IsREST() 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