registry

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: Apache-2.0 Imports: 10 Imported by: 34

Documentation

Overview

Package registry is a component for service discovery

Index

Constants

View Source
const ComponentType = "registry"

ComponentType is the components name.

Variables

View Source
var (
	// DefaultConfigSection is the section in the config to use.
	DefaultConfigSection = "registry"

	// DefaultRegistry is the default registry to use.
	DefaultRegistry = "mdns"

	// DefaultTimeout is the default timeout for the registry.
	DefaultTimeout = 100
)
View Source
var (
	// ErrNotFound is a not found error when GetService is called.
	ErrNotFound = errors.New("service not found")
	// ErrWatcherStopped is a error when watcher is stopped.
	ErrWatcherStopped = errors.New("watcher stopped")
)

Plugins is the plugins container for registries.

Functions

This section is empty.

Types

type Config

type Config struct {
	Plugin  string `json:"plugin,omitempty"  yaml:"plugin,omitempty"`
	Timeout int    `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}

Config is the configuration that can be used in a registry.

func NewConfig

func NewConfig(opts ...Option) Config

NewConfig creates a config to use with a registry.

type ConfigType

type ConfigType interface {
	// contains filtered or unexported methods
}

ConfigType is used in the functional options as type to identify a registry option. It is used over a static *Config type as this way plugins can also easilty set functional options without the complication of contexts, as was done in v4. This is possible because plugins will nest the registry.Config type, and thus inherit the interface that is used to identify the registry config.

Plugin specific option example:

	 // WithLogger option located in the MDNS registry package.
		func WithLogger(logger log.Logger) registry.Option {
		 	return func(c registry.ConfigType) {
        // The config type used here is *mdns.Config
		 	   cfg, ok := c.(*Config)
		 	   if ok {
		 	    	cfg.Logger = logger
		 	   }
		 	}
		}

type DeregisterOption

type DeregisterOption func(*DeregisterOptions)

DeregisterOption is functional option type for the deregister config.

type DeregisterOptions

type DeregisterOptions struct {
	Context context.Context
}

DeregisterOptions are the options used to deregister services.

type Endpoint

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

Endpoint represents a service endpoint in a registry.

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)

GetOption is functional option type for the get config.

type GetOptions

type GetOptions struct {
	Context context.Context
}

GetOptions are the options used to fetch a service.

type ListOption

type ListOption func(*ListOptions)

ListOption is functional option type for the list config.

type ListOptions

type ListOptions struct {
	Context context.Context
}

ListOptions are the options used to list services.

type Node

type Node struct {
	ID string `json:"id"`
	// ip:port
	Address string `json:"address"`
	// grpc/h2c/http/http3 uvm., since go-orb!
	Transport string            `json:"transport"`
	Metadata  map[string]string `json:"metadata"`
}

Node represents a service node in a registry. One service can be comprised of multiple nodes.

type Option

type Option func(ConfigType)

Option is a functional option type for the registry.

func WithPlugin added in v0.1.0

func WithPlugin(n string) Option

WithPlugin set the implementation to use.

func WithTimeout

func WithTimeout(n int) Option

WithTimeout sets the default registry timeout used.

type ProviderFunc

type ProviderFunc func(
	serviceName types.ServiceName,
	serviceVersion types.ServiceVersion,
	data types.ConfigData,
	logger log.Logger,
	opts ...Option,
) (Type, error)

ProviderFunc is provider function type used by plugins to create a new registry.

type RegisterOption

type RegisterOption func(*RegisterOptions)

RegisterOption is functional option type for the register config.

func RegisterTTL

func RegisterTTL(t time.Duration) RegisterOption

RegisterTTL sets the TTL for service registration.

type RegisterOptions

type RegisterOptions struct {
	TTL time.Duration
}

RegisterOptions are the options used to register services.

type Registry

type Registry interface {
	types.Component

	// ServiceName returns types.ServiceName that has been provided to Provide().
	ServiceName() string

	// ServiceVersion returns types.ServiceVersion that has been provided to Provide().
	ServiceVersion() string

	// Register registers a service within the registry.
	Register(srv *Service, opts ...RegisterOption) error

	// Deregister deregisters a service within the registry.
	Deregister(srv *Service, opts ...DeregisterOption) error

	// GetService returns a service from the registry.
	GetService(name string, opts ...GetOption) ([]*Service, error)

	// ListServices lists services within the registry.
	ListServices(opts ...ListOption) ([]*Service, error)

	// Watch returns a Watcher which you can watch on.
	Watch(opts ...WatchOption) (Watcher, error)
}

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

type Result

type Result struct {
	Action  string   `json:"action"`
	Service *Service `json:"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"`
}

Service represents a service in a registry.

type Type added in v0.1.0

type Type struct {
	Registry
}

Type is the registry type it is returned when you use ProvideRegistry which selects a registry to use based on the plugin configuration.

func Provide added in v0.1.0

func Provide(
	name types.ServiceName,
	version types.ServiceVersion,
	configs types.ConfigData,
	logger log.Logger,
	opts ...Option) (Type, error)

Provide is the registry provider for wire. It parses the config from "configs", fetches the "Plugin" from the config and then forwards all it's arguments to the factory which it get's from "Plugins".

type Value

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

Value is a value container used in the registry.

type WatchOption

type WatchOption func(*WatchOptions)

WatchOption is functional option type for the watch config.

func WatchService

func WatchService(name string) WatchOption

WatchService sets a service name to watch.

type WatchOptions

type WatchOptions struct {
	// Specify a service to watch
	// If blank, the watch is for all services
	Service string
}

WatchOptions are the options used by the registry watcher.

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.

Jump to

Keyboard shortcuts

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