registry

package
v0.0.0-...-4e5f079 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package registry is an interface for service discovery

Index

Constants

This section is empty.

Variables

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

Functions

func Contains

func Contains(services []Service, service Service) bool

Contains judge is service in services

func Equal

func Equal(s1, s2 Service) bool

Equal judge s1 == s2

func Format

func Format(s Service) string

Format Service to string and url encode

Types

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

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
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Registry

type Registry interface {
	Init(...Option) error
	Register(Service, ...RegisterOption) error
	Deregister(Service) error
	GetService(string) ([]Service, error)
	ListServices() ([]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, ...}

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 {
	Protocol  string
	Address   string
	Name      string
	Version   string
	Funcs     []string
	Codecs    []string
	Transport string
	Side      string
	TLS       bool
	Timestamp int64
	Labels    map[string]string
}

Service register info

func Parse

func Parse(str string) (Service, error)

Parse string to Service

type WatchOption

type WatchOption func(*WatchOptions)

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.

Directories

Path Synopsis
Package etcd provides an etcd registry
Package etcd provides an etcd registry

Jump to

Keyboard shortcuts

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