registry

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateEndpoints

func ValidateEndpoints(endpoints []string) error

ValidateEndpoints 验证终端点列表

Types

type Discovery

type Discovery interface {
	// GetService 获取服务实例
	GetService(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
	// Watch 监视服务更改
	Watch(ctx context.Context, serviceName string) (Watcher, error)
}

Discovery 是服务发现接口

type Registrar

type Registrar interface {
	// Register 注册服务实例
	Register(ctx context.Context, service *ServiceInstance) error
	// Deregister 注销服务实例
	Deregister(ctx context.Context, service *ServiceInstance) error
}

Registrar 是服务注册接口,与Registry保持一致 这样可以兼容eidola中的registry实现

type Registry

type Registry interface {
	// Register 注册服务实例
	Register(ctx context.Context, service *ServiceInstance) error
	// Deregister 注销服务实例
	Deregister(ctx context.Context, service *ServiceInstance) error
}

Registry 是服务注册接口

type RegistryConfig

type RegistryConfig struct {
	// Type 是注册中心类型
	Type RegistryType
	// Endpoints 是注册中心终端点列表
	Endpoints []string
	// Timeout 是注册中心操作超时时间
	Timeout time.Duration
	// Username 是注册中心用户名
	Username string
	// Password 是注册中心密码
	Password string
	// TLSEnabled 是否启用TLS
	TLSEnabled bool
}

RegistryConfig 是注册中心配置

type RegistryOption

type RegistryOption func(o *RegistryConfig)

RegistryOption 是注册中心选项函数

func WithCredentials

func WithCredentials(username, password string) RegistryOption

WithCredentials 设置注册中心认证信息

func WithEndpoints

func WithEndpoints(endpoints ...string) RegistryOption

WithEndpoints 设置注册中心终端点

func WithTLS

func WithTLS(enabled bool) RegistryOption

WithTLS 设置是否启用TLS

func WithTimeout

func WithTimeout(timeout time.Duration) RegistryOption

WithTimeout 设置注册中心操作超时时间

type RegistryType

type RegistryType string

RegistryType 表示注册中心类型

const (
	// Consul 注册中心类型
	Consul RegistryType = "consul"
	// Etcd 注册中心类型
	Etcd RegistryType = "etcd"
	// Zookeeper 注册中心类型
	Zookeeper RegistryType = "zookeeper"
	// Nacos 注册中心类型
	Nacos RegistryType = "nacos"
	// Eureka 注册中心类型
	Eureka RegistryType = "eureka"
	// Memory 内存注册中心类型
	Memory RegistryType = "memory"
)

type ServiceInstance

type ServiceInstance struct {
	// ID 是服务实例的唯一标识符
	ID string
	// Name 是服务实例的名称
	Name string
	// Version 是服务实例的版本
	Version string
	// Metadata 是服务实例的元数据
	Metadata map[string]string
	// Endpoints 是服务实例的终端点列表
	Endpoints []string
	// Status 是服务实例的状态
	Status ServiceInstanceStatus
	// CreatedAt 是服务实例的创建时间
	CreatedAt time.Time
	// UpdatedAt 是服务实例的更新时间
	UpdatedAt time.Time
}

ServiceInstance 表示一个服务实例

type ServiceInstanceStatus

type ServiceInstanceStatus string

ServiceInstanceStatus 表示服务实例的状态

const (
	// StatusUp 表示服务实例正常运行
	StatusUp ServiceInstanceStatus = "UP"
	// StatusDown 表示服务实例已关闭
	StatusDown ServiceInstanceStatus = "DOWN"
	// StatusUnknown 表示服务实例状态未知
	StatusUnknown ServiceInstanceStatus = "UNKNOWN"
)

type ServiceRegistrar

type ServiceRegistrar interface {
	Registry
	Discovery
}

ServiceRegistrar 是服务注册器,同时包含注册与发现功能

type Watcher

type Watcher interface {
	// Next 返回服务的下一个变更
	Next() ([]*ServiceInstance, error)
	// Stop 停止观察
	Stop() error
}

Watcher 是服务更改的观察者

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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