registry

package
v0.0.0-...-037b315 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoWatcher

type AutoWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewAutoWatcher

func NewAutoWatcher(watchName string, dis Discovery, fn func([]*Instance)) (*AutoWatcher, error)

func (*AutoWatcher) Close

func (aw *AutoWatcher) Close()

func (*AutoWatcher) Register

func (aw *AutoWatcher) Register(fn func([]*Instance))

type Discovery

type Discovery interface {
	// GetService return the service instances in memory according to the service name. if srvName is emtpy, get all service
	GetService(ctx context.Context, srvName string) ([]*Instance, error)

	// Watch creates a watcher according to the service name, if srvName is emtpy, watch all service
	Watch(ctx context.Context, srvName string) (Watcher, error)
}

Discovery is service discovery.

type Instance

type Instance struct {
	ID       string            `json:"ID,omitempty"`
	Name     string            `json:"Name,omitempty"`
	MetaData map[string]string `json:"MetaData,omitempty"`
	// Endpoints is endpoint addresses of the service instance.
	// schema:
	//   http://127.0.0.1:8000
	//   grpc://127.0.0.1:9000
	Endpoints []string `json:"Endpoints,omitempty"`
}

Instance 服务节点信息

type Registrar

type Registrar interface {
	Register(ctx context.Context, service *Instance) error
	Unregister(ctx context.Context, service *Instance) error
}

type Watcher

type Watcher interface {
	// Next returns services in the following two cases:
	// 1.the first time to watch and the service instance list is not empty.
	// 2.any service instance changes found.
	// if the above two conditions are not met, it will block until context deadline exceeded or canceled
	Next() ([]*Instance, error)
	// Stop close the watcher.
	Stop() error
}

Watcher is service watcher.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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