registry

package
v0.0.0-...-7d7ecdb Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package registry is a component for service discovery

Index

Constants

View Source
const Name = "registry"

Variables

View Source
var (
	// Not found error when GetService is called.
	ErrNotFound = errors.New("service not found")
	// Watcher stopped error when watcher is stopped.
	ErrWatcherStopped = errors.New("watcher stopped")
)
View Source
var Plugins = container.NewPlugins(
	func() Registry { return nil },
	func() any { return nil },
)

Functions

func NewConfig

func NewConfig(plugin string) (any, error)

NewConfig returns the default config for a given Plugin.

Types

type Config

type Config interface {
	config.ConfigPlugin

	// Optional
	GetLogger() *log.ConfigImpl
	GetAddresses() []string

	// Timeout in milliseconds.
	GetTimeout() int
}

type ConfigImpl

type ConfigImpl struct {
	*config.ConfigPluginImpl

	Logger    *log.ConfigImpl
	Addresses []string
	Timeout   int
}

func NewComponentConfig

func NewComponentConfig() *ConfigImpl

func (*ConfigImpl) GetAddresses

func (c *ConfigImpl) GetAddresses() []string

func (*ConfigImpl) GetLogger

func (c *ConfigImpl) GetLogger() *log.ConfigImpl

func (*ConfigImpl) GetTimeout

func (c *ConfigImpl) GetTimeout() int

func (*ConfigImpl) Merge

func (c *ConfigImpl) Merge(aPreviousConfig any) error

MergePrevious merges the previous config into this one.

type DeregisterOption

type DeregisterOption func(*DeregisterOptions)

func DeregisterContext

func DeregisterContext(ctx context.Context) DeregisterOption

type DeregisterOptions

type DeregisterOptions struct {
	Context context.Context
}

type DiConfig

type DiConfig struct{}

DiConfig is marker that DiFlags has been parsed into Config

func ProvideConfig

func ProvideConfig(
	_ di.DiConfig,
	flags DiFlags,
	cfg Config,
	c cli.Cli,
	cliConfig cli.Config,
	configDatas []config.Data,
) (DiConfig, error)

type DiFlags

type DiFlags struct{}

func ProvideFlags

func ProvideFlags(
	config Config,
	cliConfig cli.Config,
	c cli.Cli,
) (DiFlags, error)

type Endpoint

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

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 GetOption

type GetOption func(*GetOptions)

func GetContext

func GetContext(ctx context.Context) GetOption

type GetOptions

type GetOptions struct {
	Context context.Context
}

type ListOption

type ListOption func(*ListOptions)

func ListContext

func ListContext(ctx context.Context) ListOption

type ListOptions

type ListOptions struct {
	Context context.Context
}

type Node

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

type Option

type Option func(*Options)

func WithLogger

func WithLogger(n log.Logger) Option

type Options

type Options struct {
	Logger log.Logger
}

func NewOptions

func NewOptions(opts ...Option) Options

type RegisterOption

type RegisterOption func(*RegisterOptions)

func RegisterContext

func RegisterContext(ctx context.Context) 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
}

type Registry

type Registry interface {
	Init(aConfig any, opts ...Option) error
	Config() any
	Register(*Service, ...RegisterOption) error
	Deregister(*Service, ...DeregisterOption) error
	GetService(string, ...GetOption) ([]*Service, error)
	ListServices(...ListOption) ([]*Service, error)
	Watch(...WatchOption) (Watcher, error)
	String() string
}

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

func Provide

func Provide(

	_ DiConfig,
	parentLogger log.Logger,
	config Config,
) (Registry, error)

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  map[string]string `json:"metadata"`
	Endpoints []*Endpoint       `json:"endpoints"`
	Nodes     []*Node           `json:"nodes"`
}

type Value

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

type WatchOption

type WatchOption func(*WatchOptions)

func WatchContext

func WatchContext(ctx context.Context) 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
}

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