registry

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package registry is an interface for service discovery

Index

Constants

View Source
const DefaultPrefix = "/registry"

Variables

View Source
var Err = xerror.New(Name)
View Source
var ErrNotFound = Err.New("not found")
View Source
var ErrWatcherStopped = Err.New("watcher stopped")

ErrWatcherStopped Watcher stopped error when watcher is stopped

View Source
var Name = "registry"

Functions

func Init added in v0.1.0

func Init(driver string, cfg map[string]interface{}) (err error)

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 added in v0.1.2

type DeregOpt func(*DeregOpts)

func DeregContext added in v0.1.2

func DeregContext(ctx context.Context) DeregOpt

type DeregOpts added in v0.1.2

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 types.EventType
	// Timestamp is event timestamp
	Timestamp time.Time
	// Service is registry service
	Service *Service
}

Event is registry event

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 (Node) GetPort

func (t Node) GetPort() int

type Nodes added in v0.1.0

type Nodes []*Node

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

TLSConfig 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
	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(dur time.Duration) RegOpt

type RegOpts

type RegOpts struct {
	TTL     time.Duration
	Context context.Context
}

type Registry

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

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

func Default

func Default() Registry

type Result

type Result struct {
	Action  types.EventType
	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

WatchService Watch a service

type WatchOpts

type WatchOpts struct {
	Service string
	Context context.Context
}

type Watcher

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

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

Directories

Path Synopsis
Package etcdv3 provides an etcd version 3 registry
Package etcdv3 provides an etcd version 3 registry
Package gossip provides a gossip registry based on hashicorp/memberlist
Package gossip provides a gossip registry based on hashicorp/memberlist
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