registry

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRegisterInterval = time.Second * 30
	DefaultRegisterTTL      = time.Second * 90
)

Variables

View Source
var (
	DefaultRegistry   = NewRegistry()
	ErrNotFound       = errors.New("service not found")
	ErrWatcherStopped = errors.New("watcher stopped")
)

Functions

func Deregister added in v0.6.1

func Deregister(s *Service, opts ...DeregisterOption) error

Deregister 从注册表这中注销节点

func Register added in v0.6.1

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

Register 注册节点到注册表

func String added in v0.6.1

func String() string

Types

type DeregisterOption

type DeregisterOption func(*DeregisterOptions)

func OptDeregisterContext added in v1.2.0

func OptDeregisterContext(ctx context.Context) DeregisterOption

type DeregisterOptions

type DeregisterOptions struct {
	Context context.Context
}

DeregisterOptions 取消注册参数

type Event

type Event struct {
	// Id 注册的id
	Id string
	// Type 事件类型
	Type EventType
	// Timestamp 事件发生事件
	Timestamp time.Time
	// Service 注册的服务
	Service *Service
}

Event 事件

type EventType

type EventType int

EventType 服务事件类型

const (
	// Create 有一个新的服务登记
	Create EventType = iota
	// Delete 有一个服务取消登记
	Delete
	// Update 服务的信息更新了
	Update
	// Override 覆盖
	Override
)

func (EventType) String

func (t EventType) String() string

type GetOption

type GetOption func(*GetOptions)

func OptGetContext added in v1.2.0

func OptGetContext(ctx context.Context) GetOption

type GetOptions

type GetOptions struct {
	Context context.Context
}

type ListOption

type ListOption func(*ListOptions)

func OptListContext added in v1.2.0

func OptListContext(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"`
	Paths    []string          `json:"paths"`
	Metadata map[string]string `json:"metadata"`
}

Node 节点

type Option

type Option func(*Options)

func OptAddrList added in v1.2.0

func OptAddrList(addrList ...string) Option

OptAddrList 设置地址列表

func OptLeasesInterval added in v1.2.0

func OptLeasesInterval(t time.Duration) Option

OptLeasesInterval 租约续期时间

func OptSecure added in v1.2.0

func OptSecure(b bool) Option

OptSecure 是否加密

func OptServiceName added in v1.2.0

func OptServiceName(name string) Option

OptServiceName 设置服务名称

func OptServiceVersion added in v1.2.0

func OptServiceVersion(version string) Option

OptServiceVersion 设置服务版本

func OptTLSConfig added in v1.2.0

func OptTLSConfig(t *tls.Config) Option

OptTLSConfig 设置tls证书信息

func OptTimeout added in v1.2.0

func OptTimeout(t time.Duration) Option

OptTimeout 设置超时时间

type Options

type Options struct {
	AddrList  []string        // 地址列表
	Timeout   time.Duration   // 超时时间
	Secure    bool            // 是否加密
	TLSConfig *tls.Config     // tls证书配置
	Context   context.Context // 上下文系信息
}

Options 配置

type PluginRegistry

type PluginRegistry struct {
	// contains filtered or unexported fields
}

func NewRegistryPlugin

func NewRegistryPlugin(registry Registry) *PluginRegistry

NewRegistryPlugin 创建服务注册插件

func (*PluginRegistry) AfterListen

func (that *PluginRegistry) AfterListen(addr net.Addr) (err error)

AfterListen 服务启动成功,监听成功后,进行服务注册

func (*PluginRegistry) AfterRegRouter

func (that *PluginRegistry) AfterRegRouter(handler *drpc.Handler) error

func (*PluginRegistry) BeforeCloseEndpoint

func (that *PluginRegistry) BeforeCloseEndpoint(_ drpc.Endpoint) error

BeforeCloseEndpoint 关闭服务之前先取消注册

func (*PluginRegistry) Deregister

func (that *PluginRegistry) Deregister() error

Deregister 取消注册

func (*PluginRegistry) Name

func (that *PluginRegistry) Name() string

func (*PluginRegistry) Register

func (that *PluginRegistry) Register() error

Register 注册

type RegisterOption

type RegisterOption func(*RegisterOptions)

func OptRegisterContext added in v1.2.0

func OptRegisterContext(ctx context.Context) RegisterOption

OptRegisterContext 设置注册服务的上下文

func OptRegisterTTL added in v1.2.0

func OptRegisterTTL(t time.Duration) RegisterOption

OptRegisterTTL 设置服务的生存时间

type RegisterOptions

type RegisterOptions struct {
	TTL     time.Duration
	Context context.Context
}

RegisterOptions 注册配置信息

type Registry

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

Registry 服务注册接口

func NewRegistry

func NewRegistry(opts ...Option) Registry

type Result

type Result struct {
	Action  EventType
	Service *Service
}

Result 监视器返回对象

type Service

type Service struct {
	Name     string            `json:"name"`
	Version  string            `json:"version"`
	Metadata map[string]string `json:"metadata"`
	Nodes    []*Node           `json:"nodes"`
}

Service 服务

func GetService added in v0.6.1

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

GetService 通过服务名获取服务列表,为什么返回的是一个数组?因为服务是有版本区别的,多个版本的服务是可以共存的

func ListServices added in v0.6.1

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

ListServices 获取所有服务的列表

type WatchOption

type WatchOption func(*WatchOptions)

func OptWatchContext added in v1.2.0

func OptWatchContext(ctx context.Context) WatchOption

OptWatchContext 监视器的上下文

func OptWatchService added in v1.2.0

func OptWatchService(name string) WatchOption

OptWatchService 监视器监听指定的服务

type WatchOptions

type WatchOptions struct {
	Service string
	Context context.Context
}

WatchOptions 监视器参数

type Watcher

type Watcher interface {
	// Next 是一个阻塞调用
	Next() (*Result, error)
	Stop()
}

Watcher 服务监视器

func Watch added in v0.6.1

func Watch(opts ...WatchOption) (Watcher, error)

Watch 监听服务变化

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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