registry

package
v0.88.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package registry 服务注册与发现

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Selector2Director

func Selector2Director(s selector.Selector) func(r *http.Request)

Selector2Director 将 selector.Selector 转换为 httputil.ProxyRequest.Director 字段类型的函数

func Selector2Rewrite

func Selector2Rewrite(s selector.Selector) func(r *httputil.ProxyRequest)

Selector2Rewrite 将 selector.Selector 转换为 httputil.ProxyRequest.Rewrite 字段类型的函数

Types

type DeregisterFunc

type DeregisterFunc = func() error

DeregisterFunc 注销微服务的函数签名

type Registry

type Registry interface {
	// Register 注册服务
	//
	// name 服务名称;
	// peer 节点信息;
	//
	// 返回一个用于注销当前服务的方法;
	Register(name string, peer selector.Peer) (DeregisterFunc, error)

	// Discover 返回指定名称的服务节点
	//
	// name 为服务的名称;
	// s 为调用者关联的 [web.Server] 对象;
	Discover(name string, s web.Server) selector.Selector

	// ReverseProxy 返回 name 对应的 [httputil.ReverseProxy]
	ReverseProxy(string, web.Server) *httputil.ReverseProxy
}

Registry 服务注册与发现需要实现的接口

func NewCache

func NewCache(c web.Cache, s *Strategy, freq time.Duration) Registry

NewCache 基于 web.CacheRegistry 实现

freq 表示从缓存系统中获取数据的频率;

type Strategy

type Strategy struct {
	// NewSelector 构建 [selector.Updateable]
	NewSelector func() selector.Updateable

	// NewPeer 构建与 [Strategy.NewSelector] 相匹配的 [selector.Peer] 零值对象
	NewPeer func() selector.Peer
}

Strategy 为初始化 Registry 对象提供的方案

func NewRandomStrategy

func NewRandomStrategy() *Strategy

func NewRoundRobinStrategy

func NewRoundRobinStrategy() *Strategy

func NewStrategy

func NewStrategy(sel func() selector.Updateable, p func() selector.Peer) *Strategy

func NewWeightedRandomStrategy

func NewWeightedRandomStrategy() *Strategy

func NewWeightedRoundRobinStrategy

func NewWeightedRoundRobinStrategy() *Strategy

Jump to

Keyboard shortcuts

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