discovery

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: LGPL-2.1 Imports: 7 Imported by: 0

Documentation

Overview

+k8s:deepcopy-gen=package

Index

Constants

This section is empty.

Variables

View Source
var (
	Name  = plugin.Name
	Using = plugin.Using
)
View Source
var (
	// ErrRegistry dsync errors.
	ErrRegistry = errors.New("registry")
	// ErrNotFound Not found error when IRegistry.GetService or IRegistry.GetServiceNode is called
	ErrNotFound = fmt.Errorf("%w: service not found", ErrRegistry)
	// ErrStoppedWatching Stopped watching error when watcher is stopped
	ErrStoppedWatching = fmt.Errorf("%w: stopped watching", ErrRegistry)
)

Functions

func Deregister

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

Deregister 取消注册服务

func Register

func Register(servCtx service.Context, ctx context.Context, service *Service, ttl time.Duration) error

Register 注册服务

Types

type Event

type Event struct {
	Type    EventType `json:"type"`
	Service *Service  `json:"service"`
}

Event is returned by a call to Next on the watcher. Type can be create, update, delete +k8s:deepcopy-gen=true

func (*Event) DeepCopy

func (in *Event) DeepCopy() *Event

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Event.

func (*Event) DeepCopyInto

func (in *Event) DeepCopyInto(out *Event)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type EventType

type EventType int

EventType defines registry event type

const (
	// Create is emitted when a new service is registered
	Create EventType = iota
	// Delete is emitted when an existing service is deregsitered
	Delete
	// Update is emitted when an existing service is updated
	Update
)

func (*EventType) MarshalText

func (t *EventType) MarshalText() ([]byte, error)

MarshalText marshals the EventType to text.

func (*EventType) Set

func (t *EventType) Set(str string) error

Set converts a EventType string into a EventType value. returns error if the input string does not match known values.

func (EventType) String

func (t EventType) String() string

String returns human readable EventType.

func (*EventType) UnmarshalText

func (t *EventType) UnmarshalText(text []byte) error

UnmarshalText unmarshals text to a EventType.

type IRegistry

type IRegistry interface {
	// Register 注册服务
	Register(ctx context.Context, service *Service, ttl time.Duration) error
	// Deregister 取消注册服务
	Deregister(ctx context.Context, service *Service) error
	// GetServiceNode 查询服务节点
	GetServiceNode(ctx context.Context, serviceName, nodeId string) (*Service, error)
	// GetService 查询服务
	GetService(ctx context.Context, serviceName string) ([]Service, error)
	// ListServices 查询所有服务
	ListServices(ctx context.Context) ([]Service, error)
	// Watch 获取服务监听器
	Watch(ctx context.Context, pattern string) (IWatcher, error)
}

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

type IWatcher

type IWatcher interface {
	// Pattern watching pattern
	Pattern() string
	// Next is a blocking call
	Next() (*Event, error)
	// Stop stop watching
	Stop() <-chan struct{}
}

IWatcher is an interface that returns updates about services within the registry.

func Watch

func Watch(servCtx service.Context, ctx context.Context, serviceName string) (IWatcher, error)

Watch 获取服务监听器

type Node

type Node struct {
	Id      string            `json:"id"`      // 节点ID
	Address string            `json:"address"` // 节点的地址
	Meta    map[string]string `json:"meta"`    // 节点元数据,以键值对的形式保存附加信息
}

Node 服务节点 +k8s:deepcopy-gen=true

func (*Node) DeepCopy

func (in *Node) DeepCopy() *Node

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Node.

func (*Node) DeepCopyInto

func (in *Node) DeepCopyInto(out *Node)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Service

type Service struct {
	Name    string            `json:"name"`    // 服务名称
	Version string            `json:"version"` // 服务版本号
	Meta    map[string]string `json:"meta"`    // 服务元数据,以键值对的形式保存附加信息
	Nodes   []Node            `json:"nodes"`   // 服务节点列表
}

Service 服务配置 +k8s:deepcopy-gen=true

func GetService

func GetService(servCtx service.Context, ctx context.Context, serviceName string) ([]Service, error)

GetService 查询服务

func ListServices

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

ListServices 查询所有服务

func (*Service) DeepCopy

func (in *Service) DeepCopy() *Service

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Service.

func (*Service) DeepCopyInto

func (in *Service) DeepCopyInto(out *Service)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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