registry

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 5 Imported by: 22

README

Service Registry

Service Registry registers service nodes and reports healthy by interacting with service registry center.

Service Registry Interface

// Registry is the service registry interface.
type Registry interface {
	Register(service string, opt ...Option) error
	Deregister(service string) error
}

The custom implementation should refer to the implementation inside that project.

Documentation

Overview

Package registry registers servers. A server report itself on start.

Index

Constants

View Source
const GracefulRestart = EventType(iota)

GracefulRestart represents the hot restart event.

Variables

View Source
var ErrNotImplement = errors.New("not implement")

ErrNotImplement is the not implemented error.

Functions

func Register

func Register(name string, s Registry)

Register registers a named registry. Each service has its own registry.

func SetDefaultRegistry

func SetDefaultRegistry(r Registry)

SetDefaultRegistry sets the default registry.

Types

type EventType

type EventType int

EventType defines the event types.

type Node

type Node struct {
	ServiceName   string        // 服务名
	ContainerName string        // 容器名
	Address       string        // 目标地址 ip:port
	Network       string        // 网络层协议 tcp/udp
	Protocol      string        // 业务协议 trpc/http
	SetName       string        // 节点 Set 名
	Weight        int           // 权重
	CostTime      time.Duration // 当次请求耗时
	EnvKey        string        // 透传的环境信息
	Metadata      map[string]interface{}
	// ParseAddr should be used to convert Node to net.Addr if it's not nil.
	// See test case TestSelectorRemoteAddrUseUserProvidedParser in client package.
	ParseAddr func(network, address string) net.Addr
}

Node is the information of a node.

func (*Node) String

func (n *Node) String() string

String returns an abbreviation information of node.

type NoopRegistry

type NoopRegistry struct{}

NoopRegistry is the noop registry.

func (*NoopRegistry) Deregister

func (noop *NoopRegistry) Deregister(service string) error

Deregister always return ErrNotImplement.

func (*NoopRegistry) Register

func (noop *NoopRegistry) Register(service string, opt ...Option) error

Register always returns ErrNotImplement.

type Option

type Option func(*Options)

Option modifies the Options.

func WithAddress

func WithAddress(s string) Option

WithAddress returns an Option which sets the server address. The format of address is "IP:Port" or just ":Port".

func WithEvent

func WithEvent(e EventType) Option

WithEvent returns an Option which sets the event type.

type Options

type Options struct {
	Address string
	Event   EventType
}

Options is the node register options.

type Registry

type Registry interface {
	Register(service string, opt ...Option) error
	Deregister(service string) error
}

Registry is the interface that defines a register.

var DefaultRegistry Registry = &NoopRegistry{}

DefaultRegistry is the default registry.

func Get

func Get(name string) Registry

Get gets a named registry.

Jump to

Keyboard shortcuts

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