discovery

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package discovery 提供服务发现的抽象接口,供 gRPC resolver 等客户端组件使用。

Discovery 与 registry 互补:registry 负责「注册自身」, discovery 负责「发现其他服务实例」。

默认提供 noop 实现(不返回任何服务),适用于无需服务发现的场景。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWatcherStopped 表示 Watcher 已停止,Next 不应再被调用。
	ErrWatcherStopped = errors.New("watcher stopped")
	// ErrTimeout 表示等待服务变更超时。
	ErrTimeout = errors.New("watcher timeout")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Interval  time.Duration `yaml:"interval"`
	Driver    string        `yaml:"driver"`
	DriverCfg *config.Node  `yaml:"driver_config"`
}

func (*Config) Check

func (cfg *Config) Check() *Config

Check 校验配置必填字段,Driver 为空时 panic。

type Discovery

type Discovery interface {
	String() string
	Watch(ctx context.Context, srv string, opts ...WatchOpt) result.Result[Watcher]
	GetService(ctx context.Context, srv string, opts ...GetOpt) result.Result[[]*service.Service]
}

Discovery 是服务发现接口。

func NewNoopDiscovery

func NewNoopDiscovery() Discovery

NewNoopDiscovery 返回一个不执行任何服务发现的 Discovery 实现。

type EventType

type EventType int32

EventType 表示服务变更类型。

const (
	EventType_UNKNOWN EventType = 0
	EventType_CREATE  EventType = 1
	EventType_UPDATE  EventType = 2
	EventType_DELETE  EventType = 3
)

type GetOpt

type GetOpt func(*GetOpts)

type GetOpts

type GetOpts struct {
	Timeout time.Duration
}

type Result

type Result struct {
	Action  EventType
	Service *service.Service
}

Result 是 Watcher.Next 返回的单次变更事件。

type WatchOpt

type WatchOpt func(*WatchOpts)

type WatchOpts

type WatchOpts struct {
	Service string
}

type Watcher

type Watcher interface {
	Next() result.Result[*Result]
	Stop() error
}

Watcher 监听服务实例变更,Next 为阻塞调用。

Jump to

Keyboard shortcuts

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