registry

package
v0.2.10-7 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package registry is an interface for service discovery

Index

Constants

View Source
const (
	// DefaultMaxMsgSize define maximum message size that server can send or receive.
	// Default value is 4MB.
	DefaultMaxMsgSize = 1024 * 1024 * 4

	DefaultSleepAfterDeRegister = time.Second * 2

	// DefaultRegisterTTL The register expiry time
	DefaultRegisterTTL = time.Minute

	// DefaultRegisterInterval The interval on which to register
	DefaultRegisterInterval = time.Second * 30

	DefaultSleepAfterDeregister = time.Second * 2
)
View Source
const DefaultPrefix = "/registry"

Variables

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

ErrWatcherStopped Watcher stopped error when watcher is stopped

View Source
var Name = "registry"

Functions

func New added in v0.2.11

func New(c *Config, lifecycle lifecycle.Lifecycle, regs map[string]Registry)

func SetDefault

func SetDefault(r Registry)

Types

type Config added in v0.2.11

type Config struct {
	RegisterInterval time.Duration          `yaml:"registerInterval"`
	Driver           string                 `json:"driver" yaml:"driver"`
	DriverCfg        map[string]interface{} `json:"driver_config" yaml:"driver_config"`
}

func DefaultCfg

func DefaultCfg() Config

func (*Config) Check added in v0.2.11

func (cfg *Config) Check() *Config

type DeregOpt

type DeregOpt func(*DeregOpts)

func DeregContext

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

Event is registry event

type GetOpt

type GetOpt func(*GetOpts)

type GetOpts

type GetOpts struct {
	Timeout time.Duration
	Context context.Context
}

type ListOpt

type ListOpt func(*ListOpts)

func ListContext

func ListContext(ctx context.Context) ListOpt

type ListOpts

type ListOpts struct {
	Context context.Context
}

type Loader added in v0.2.2

type Loader struct{}

type Node

type Node struct {
	Id       string            `json:"id,omitempty"`
	Version  string            `json:"version,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

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) result.Result[Watcher]
	ListService(...ListOpt) result.Result[[]*Service]
	GetService(string, ...GetOpt) result.Result[[]*Service]
}

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  eventpbv1.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"`
	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.Result[*Result]
	Stop() error
}

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

Directories

Path Synopsis
drivers
k8s
mdns
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