registry

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Flag pflag.FlagSet for registry
	Flag = pflag.NewFlagSet("registry", pflag.ExitOnError)

	DefaultRegistry        Registry
	DefaultRegistryTimeout = time.Second * 3

	// ErrNotFound not found error when GetService is called
	ErrNotFound = errors.New("service not found")
	// ErrWatcherStopped watcher stopped error when watcher is stopped
	ErrWatcherStopped = errors.New("watcher stopped")
)

Functions

func Deregister

func Deregister(ctx context.Context, s *Service) error

Deregister a service node

func Register

func Register(ctx context.Context, s *Service, opts ...RegisterOption) error

Register a service node. Additionally supply options such as TTL.

func String

func String() string

Types

type DeregisterOption

type DeregisterOption func(*DeregisterOptions)

type DeregisterOptions

type DeregisterOptions struct {
}

type Endpoint added in v0.23.0

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"`
}

Endpoint is a endpoint provided by a service

type Event added in v0.23.0

type Event struct {
	// Event Id
	Id string `json:"id,omitempty"`
	// type of event
	Type EventType `json:"type,omitempty"`
	// unix timestamp of event
	Timestamp int64 `json:"timestamp,omitempty"`
	// service entry
	Service *Service `json:"service,omitempty"`
}

Event is registry event

type EventType added in v0.23.0

type EventType string
const (
	EventCreate EventType = "Create"
	EventUpdate EventType = "Update"
	EventDelete EventType = "Delete"
)

type GetOption

type GetOption func(*GetOptions)

type GetOptions

type GetOptions struct {
}

type ListOption

type ListOption func(*ListOptions)

type ListOptions

type ListOptions struct {
}

type Node added in v0.23.0

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

Node represents the node the service is on

type OpenAPIOption

type OpenAPIOption func(*OpenAPIOptions)

type OpenAPIOptions

type OpenAPIOptions struct {
}

type Option

type Option func(*Options)

func Addrs

func Addrs(addrs ...string) Option

Addrs is the registry addresses to use

func Secure

func Secure(b bool) Option

Secure communication with the registry

func TLSConfig

func TLSConfig(t *tls.Config) Option

TLSConfig Specify TLS Config

func Timeout

func Timeout(t time.Duration) Option

type Options

type Options 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 RegisterOption

type RegisterOption func(*RegisterOptions)

func RegisterTTL

func RegisterTTL(t time.Duration) RegisterOption

type RegisterOptions

type RegisterOptions struct {
	TTL time.Duration
}

type Registry

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

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

type Result added in v0.23.0

type Result struct {
	Action    string   `json:"action,omitempty"`
	Service   *Service `json:"service,omitempty"`
	Timestamp int64    `json:"timestamp,omitempty"`
}

Result is returns by the watcher

type Service added in v0.23.0

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"`
	TTL       int64             `json:"ttl,omitempty"`
}

Service represents a vine service

func GetService

func GetService(ctx context.Context, name string) ([]*Service, error)

GetService retrieve a service. A slice is returned since we separate Name/Version.

func ListServices

func ListServices(ctx context.Context) ([]*Service, error)

ListServices list the services. Only returns service names

type Value added in v0.23.0

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

Value is an opaque value for a request or response

type WatchOption

type WatchOption func(*WatchOptions)

func WatchService

func WatchService(name string) WatchOption

WatchService watches a service

type WatchOptions

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

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.

func Watch

func Watch(ctx context.Context, opts ...WatchOption) (Watcher, error)

Watch returns a watcher which allows you to track updates to the registry.

Directories

Path Synopsis
Package mdns provides a multicast dns registry
Package mdns provides a multicast dns registry
Package memory provides an in-memory registry
Package memory provides an in-memory registry

Jump to

Keyboard shortcuts

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