registry

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package registry is an interface for service discovery

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("[registry] not found")
View Source
var ErrWatcherStopped = errors.New("[registry] watcher stopped")

Watcher stopped error when watcher is stopped

View Source
var Name = "registry"
View Source
var Prefix = "/registry"

Functions

func Register

func Register(name string, r Factory)

Types

type Cfg

type Cfg struct {
	Driver string `json:"driver"`
}

func GetDefaultCfg

func GetDefaultCfg() Cfg

func (Cfg) Build

func (cfg Cfg) Build() (_ Registry, err error)

type DeRegOpt

type DeRegOpt func(*DeRegOpts)

func DeRegisterContext

func DeRegisterContext(ctx context.Context) DeRegOpt

type DeRegOpts

type DeRegOpts struct {
	Context context.Context
}

type Endpoint

type Endpoint struct {
	Name     string            `json:"name,omitempty"`
	Request  *Value            `json:"request,omitempty"`
	Response *Value            `json:"response,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

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

func (EventType) String

func (t EventType) String() string

String returns human readable event type

type Factory

type Factory func(map[string]interface{}) (Registry, error)

type GetOpt

type GetOpt func(*GetOpts)

type GetOpts

type GetOpts struct {
	Timeout time.Duration
}

type ListOpt

type ListOpt func(*ListOpts)

func ListContext

func ListContext(ctx context.Context) ListOpt

type ListOpts

type ListOpts struct {
	Context context.Context
}

type Node

type Node struct {
	Id       string            `json:"id,omitempty"`
	Address  string            `json:"address,omitempty"`
	Port     int               `json:"port,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

func NodeOf

func NodeOf(nodes ...*Node) []*Node

func (Node) GetPort

func (t Node) GetPort() int

type Opt

type Opt func(*Opts)

func Addrs

func Addrs(addrs ...string) Opt

Addrs is the registry addresses to use

func Secure

func Secure(b bool) Opt

Secure communication with the registry

func Services

func Services(s map[string][]*Service) Opt

Services is an option that preloads service data

func TLSConfig

func TLSConfig(t *tls.Config) Opt

Specify TLS Config

func Timeout

func Timeout(t time.Duration) Opt

type Opts

type Opts struct {
	Addrs     []string
	Timeout   time.Duration
	Secure    bool
	TLSConfig *tls.Config
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type RegOpt

type RegOpt func(*RegOpts)

func RegisterContext

func RegisterContext(ctx context.Context) RegOpt

func RegisterTTL

func RegisterTTL(t time.Duration) RegOpt

func TTL

func TTL(t string) RegOpt

type RegOpts

type RegOpts struct {
	TTL time.Duration
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Registry

type Registry interface {
	Register(*Service, ...RegOpt) error
	DeRegister(*Service, ...DeRegOpt) error
	GetService(string, ...GetOpt) ([]*Service, error)
	ListServices(...ListOpt) ([]*Service, error)
	Watch(string, ...WatchOpt) (Watcher, error)
	String() string
}

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

func Default

func Default() 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,omitempty"`
	Version   string            `json:"version,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
	Endpoints []*Endpoint       `json:"endpoints,omitempty"`
	Nodes     []*Node           `json:"nodes,omitempty"`
}

type Value

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

type WatchOpt

type WatchOpt func(*WatchOpts)

func WatchContext

func WatchContext(ctx context.Context) WatchOpt

func WatchService

func WatchService(name string) WatchOpt

Watch a service

type WatchOpts

type WatchOpts 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

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

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

Directories

Path Synopsis
Package mdns is a multicast dns registry
Package mdns is a multicast dns registry

Jump to

Keyboard shortcuts

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