registry

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MulanPSL-2.0 Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound ErrNotFound
	ErrNotFound = errors.New("not found")
)

Functions

func DecodeMetadata

func DecodeMetadata(tags []string) map[string]string

func DecodeVersion

func DecodeVersion(tags []string) (string, bool)

func EncodeEndpoints

func EncodeEndpoints(en []*Endpoint) []string

func EncodeMetadata

func EncodeMetadata(md map[string]string) []string

func EncodeVersion

func EncodeVersion(v string) []string

Types

type Endpoint

type Endpoint struct {
	Name     string            `json:"name"`
	Request  *Value            `json:"request"`
	Response *Value            `json:"response"`
	Metadata map[string]string `json:"metadata"`
}

Endpoint 服务节点信息

func DecodeEndpoints

func DecodeEndpoints(tags []string) []*Endpoint

type KVResult

type KVResult struct {
	Key   string
	Value interface{}
}

type Node

type Node struct {
	Id       string            `json:"id"`
	Address  string            `json:"address"`
	Port     int               `json:"port"`
	Metadata map[string]string `json:"metadata"`
}

Node 服务节点信息

type Option

type Option func(*Options)

type Options

type Options struct {
	Address   []string
	Timeout   time.Duration
	Secure    bool
	TLSConfig *tls.Config

	Context context.Context
}

type RegisterOption

type RegisterOption func(*RegisterOptions)

func RegisterTTL

func RegisterTTL(t time.Duration) RegisterOption

type RegisterOptions

type RegisterOptions struct {
	TTL     time.Duration
	Context context.Context
}

type Registry

type Registry interface {
	Init(...Option) error
	Options() Options
	Register(*Service, ...RegisterOption) error
	Deregister(*Service) error
	GetService(string) ([]*Service, error)
	ListServices() ([]*Service, error)
	Watch(...WatchOption) (Watcher, error)
	String() string

	//KV存储
	Put(key string, value interface{}) (err error)
	Get(key string) (rsp *KVResult, err error)
	Delete(key string) (err error)
	BlockingQuery(targetPointer interface{}, prefix interface{}, call func(value interface{}))
}

Registry 注册表为服务发现提供了一个接口,以及对不同实现的抽象{consul, etcd, zookeeper, ...}

type Result

type Result struct {
	Action  string
	Service *Service
}

Result 调用Next on返回结果,观察者。操作可以是创建、更新、删除

type Service

type Service struct {
	Name      string            `json:"name"`
	Version   string            `json:"version"`
	Metadata  map[string]string `json:"metadata"`
	Endpoints []*Endpoint       `json:"endpoints"`
	Nodes     []*Node           `json:"nodes"`
}

type Value

type Value struct {
	Name   string   `json:"name"`
	Type   string   `json:"type"`
	Values []*Value `json:"values"`
}

Value Value

type WatchOption

type WatchOption func(*WatchOptions)

func WatchService

func WatchService(name string) WatchOption

WatchService a service

type WatchOptions

type WatchOptions struct {
	//Service 指定要监视的服务,如果为空,则适用于所有服务
	Service string
	Context context.Context
}

type Watcher

type Watcher interface {
	// Next is a blocking call
	Next() (*Result, error)
	Stop()
}

Watcher 是一个返回更新的接口,关于注册表中的服务。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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