serviceregdisc

package
v0.0.0-...-ecbad0b Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 6 Imported by: 0

README

服务注册与发现

service register and discovery

Documentation

Index

Constants

View Source
const (
	RootPath = "service/endpoint"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Register(ctx context.Context, path string, data []byte) error
	Discovery(ctx context.Context, path string, event chan *DiscoverEvent)
}

Client 数据存储客户端接口

type DiscoverEvent

type DiscoverEvent struct {
	Server [][]byte
}

type RegisterDiscovery

type RegisterDiscovery struct {
	// contains filtered or unexported fields
}

RegisterDiscovery 服务注册和发现对象

func NewRegDisc

func NewRegDisc(prefix string, cli Client) *RegisterDiscovery

NewRegDisc 创建服务注册和发现对象

func (*RegisterDiscovery) Discovery

func (rd *RegisterDiscovery) Discovery(ctx context.Context, path string) (<-chan *DiscoverEvent, error)

Discovery 服务发现 DiscoverEvent 通过chan DiscoverEvent 通知服务信息变更 path:要发现的服务,比如/cc/service/endpoint/user 用户服务

func (*RegisterDiscovery) GetServicePath

func (rd *RegisterDiscovery) GetServicePath(id string) string

GetServicePath 格式化服务路径

func (*RegisterDiscovery) Register

func (rd *RegisterDiscovery) Register(ctx context.Context, id string, info ServerInfo) error

Register 服务注册 id 服务ID,info 服务信息

type Server

type Server struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Server 对应一个服务对象

func NewServerDiscover

func NewServerDiscover(ctx context.Context, path string, discover RegisterDiscovery) (*Server, error)

NewServerDiscover 创建对应服务的发现对象 每个服务独立的发现对象,依赖哪些服务时,按需创建即可

func (*Server) GetServer

func (s *Server) GetServer() string

GetServer 获取一个服务地址 从服务的所有节点里面获取一个节点,通过轮询的方式返回服务地址

type ServerInfo

type ServerInfo struct {
	IP     string `json:"ip"`
	Port   string `json:"port"`
	Schema string `json:"schema"` //协议,比如https
	UUID   string `json:"uuid"`
}

ServerInfo 服务信息

func (*ServerInfo) GetAddress

func (s *ServerInfo) GetAddress() string

GetAddress 获取服务地址

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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