registry

package
v3.1.9 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package registry is an interface for service discovery

Index

Constants

View Source
const (
	// WildcardDomain indicates any domain
	WildcardDomain = "*"
	// DefaultDomain to use if none was provided in options
	DefaultDomain = "micro"
)

Variables

View Source
var (
	// DefaultRegistry is the global default registry
	DefaultRegistry Registry = NewRegistry()
	// ErrNotFound returned when GetService is called and no services found
	ErrNotFound = errors.New("service not found")
	// ErrWatcherStopped returned when when watcher is stopped
	ErrWatcherStopped = errors.New("watcher stopped")
)

Functions

func NewContext added in v3.1.0

func NewContext(ctx context.Context, c Registry) context.Context

NewContext put registry in context

Types

type DeregisterOption

type DeregisterOption func(*DeregisterOptions)

DeregisterOption option is used to deregister service

func DeregisterContext

func DeregisterContext(ctx context.Context) DeregisterOption

func DeregisterDomain

func DeregisterDomain(d string) DeregisterOption

func DeregisterTimeout

func DeregisterTimeout(t int) DeregisterOption

type DeregisterOptions

type DeregisterOptions struct {
	Context context.Context
	// Domain the service was registered in
	Domain string
	// Atempts specify max attempts for deregister
	Attempts int
}

func NewDeregisterOptions

func NewDeregisterOptions(opts ...DeregisterOption) DeregisterOptions

type Endpoint

type Endpoint struct {
	Name     string            `json:"name"`
	Request  *Value            `json:"request"`
	Response *Value            `json:"response"`
	Metadata metadata.Metadata `json:"metadata"`
}

Endpoint holds endpoint registry info

func ExtractEndpoint

func ExtractEndpoint(method reflect.Method) *Endpoint

ExtractEndpoint extract *Endpoint from reflect.Method

type Event

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

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 deregistered
	Delete
	// Update is emitted when an existing service is updated
	Update
)

func (EventType) String

func (t EventType) String() string

String returns human readable event type

type GetOption

type GetOption func(*GetOptions)

GetOption option is used to get service

func GetContext

func GetContext(ctx context.Context) GetOption

func GetDomain

func GetDomain(d string) GetOption

type GetOptions

type GetOptions struct {
	Context context.Context
	// Domain to scope the request to
	Domain string
}

func NewGetOptions

func NewGetOptions(opts ...GetOption) GetOptions

type ListOption

type ListOption func(*ListOptions)

ListOption option is used to list services

func ListContext

func ListContext(ctx context.Context) ListOption

func ListDomain

func ListDomain(d string) ListOption

type ListOptions

type ListOptions struct {
	Context context.Context
	// Domain to scope the request to
	Domain string
}

func NewListOptions

func NewListOptions(opts ...ListOption) ListOptions

type Node

type Node struct {
	Id       string            `json:"id"`
	Address  string            `json:"address"`
	Metadata metadata.Metadata `json:"metadata"`
}

Node holds node registry info

type Option

type Option func(*Options)

Option func signature

func Addrs

func Addrs(addrs ...string) Option

Addrs is the registry addresses to use

func Context

func Context(ctx context.Context) Option

Context sets the context

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Meter added in v3.1.6

func Meter(m meter.Meter) Option

Meter sets the meter

func SetOption added in v3.1.0

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

func TLSConfig

func TLSConfig(t *tls.Config) Option

Specify TLS Config

func Timeout

func Timeout(t time.Duration) Option

func Tracer added in v3.1.6

func Tracer(t tracer.Tracer) Option

Tracer sets the tracer

type Options

type Options struct {
	Addrs     []string
	Timeout   time.Duration
	TLSConfig *tls.Config

	// Logger that will be used
	Logger logger.Logger
	// Meter that will be used
	Meter meter.Meter
	// Tracer
	Tracer tracer.Tracer
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

func NewOptions

func NewOptions(opts ...Option) Options

type RegisterOption

type RegisterOption func(*RegisterOptions)

RegisterOption option is used to register service

func RegisterAttempts

func RegisterAttempts(t int) RegisterOption

func RegisterContext

func RegisterContext(ctx context.Context) RegisterOption

func RegisterDomain

func RegisterDomain(d string) RegisterOption

func RegisterTTL

func RegisterTTL(t time.Duration) RegisterOption

type RegisterOptions

type RegisterOptions struct {
	TTL time.Duration
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	// Domain to register the service in
	Domain string
	// Attempts specify attempts for register
	Attempts int
}

func NewRegisterOptions

func NewRegisterOptions(opts ...RegisterOption) RegisterOptions

type Registry

type Registry interface {
	Init(...Option) error
	Options() Options
	Connect(context.Context) error
	Disconnect(context.Context) error
	Register(context.Context, *Service, ...RegisterOption) error
	Deregister(context.Context, *Service, ...DeregisterOption) error
	GetService(context.Context, string, ...GetOption) ([]*Service, error)
	ListServices(context.Context, ...ListOption) ([]*Service, error)
	Watch(context.Context, ...WatchOption) (Watcher, error)
	String() string
}

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

func FromContext added in v3.1.0

func FromContext(ctx context.Context) (Registry, bool)

FromContext get registry from context

func NewRegistry

func NewRegistry(opts ...Option) Registry

NewRegistry returns a new noop registry

type Result

type Result struct {
	Action  string
	Service *Service
}

Result is returned by a call to Next on the watcher. Actions can be create, update, delete

type Service

type Service struct {
	Name      string            `json:"name"`
	Version   string            `json:"version"`
	Metadata  metadata.Metadata `json:"metadata"`
	Endpoints []*Endpoint       `json:"endpoints"`
	Nodes     []*Node           `json:"nodes"`
}

Service holds service registry info

type Value

type Value struct {
	Name   string   `json:"name"`
	Type   string   `json:"type"`
	Values []*Value `json:"values"`
}

Value holds additional kv stuff

func ExtractSubValue

func ExtractSubValue(typ reflect.Type) *Value

ExtractSubValue exctact *Value from reflect.Type

func ExtractValue

func ExtractValue(v reflect.Type, d int) *Value

Extract *Value from reflect.Type

type WatchOption

type WatchOption func(*WatchOptions)

WatchOption option is used to watch service changes

func WatchContext

func WatchContext(ctx context.Context) WatchOption

func WatchDomain

func WatchDomain(d string) WatchOption

func WatchService

func WatchService(name string) WatchOption

Watch a service

type WatchOptions

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
	// Domain to watch
	Domain string
}

func NewWatchOptions

func NewWatchOptions(opts ...WatchOption) WatchOptions

type Watcher

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

Watcher is an interface that returns updates about services within the registry.

Jump to

Keyboard shortcuts

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