registry

package
v1.4.18 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package registry is an interface for service discovery

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultRegistry 默认注册中心
	DefaultRegistry = newConsulRegistry()
	// ErrNotFound ErrNotFound
	ErrNotFound = errors.New("not found")
)

Functions

func Deregister

func Deregister(s *Service) error

Deregister a service node

func Register

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

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

func String

func String() string

String String

Types

type Endpoint

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

Endpoint 服务节点信息

type Node

type Node struct {
	ID       string            `json:"id"`
	Address  string            `json:"address"`
	Port     int               `json:"port"`
	Metadata map[string]string `json:"metadata"`
}

Node 服务节点信息

type Option

type Option func(*Options)

Option Option

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 TLS Config

func Timeout

func Timeout(t time.Duration) Option

Timeout Timeout

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
}

Options Options

type RegisterOption

type RegisterOption func(*RegisterOptions)

RegisterOption RegisterOption

func RegisterTTL

func RegisterTTL(t time.Duration) RegisterOption

RegisterTTL ttl

type RegisterOptions

type RegisterOptions struct {
	TTL time.Duration
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

RegisterOptions RegisterOptions

type Registry

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

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

func NewRegistry

func NewRegistry(opts ...Option) Registry

NewRegistry 新建注册中心

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

Service Service

func GetService

func GetService(name string) ([]*Service, error)

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

func ListServices

func ListServices() ([]*Service, error)

ListServices List the services. Only returns service names

type Value

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

Value Value

type WatchOption

type WatchOption func(*WatchOptions)

WatchOption WatchOption

func WatchService

func WatchService(name string) WatchOption

WatchService 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
}

WatchOptions WatchOptions

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(opts ...WatchOption) (Watcher, error)

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

Directories

Path Synopsis
Package etcdv3 provides an etcd version 3 registry
Package etcdv3 provides an etcd version 3 registry

Jump to

Keyboard shortcuts

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