sylvain

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 10 Imported by: 0

README

Sylvain

sylvain 定位是提供服务注册发现的能力, 快速结合 etcd 的 API 实现服务注册发现。

现在开始

请将 Go 升级到 ^1.17

go get -u github.com/luoyangwei/sylvain

例子

provider

查看 example/provider

// etcd 节点
endpoints := sylvain.NewEtcdEndpoints([]string{"127.0.0.1:2379"}, 5*time.Second)
// 将 provider 注册到 etcd
_ = sylvain.NewNamedServerDiscover(endpoints, sylvain.WithServerNamed("provider"), sylvain.WithServerPort(8888))
customer

查看 example/customer

// etcd 节点
endpoints := sylvain.NewEtcdEndpoints([]string{"127.0.0.1:2379"}, 5*time.Second)
// 将 customer 注册到 etcd
serverDiscover := sylvain.NewNamedServerDiscover(endpoints, sylvain.WithServerNamed("customer"), sylvain.WithServerPort(9999))
// 发现 provider
providerServer := serverDiscover.ElectionServerEndpoint("provider")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*clientv3.Client
}

Client 包装自 etcd 的 client 客户端,负责调用 etcd 的 client 客户端

func NewEtcdEndpoints

func NewEtcdEndpoints(endpoints []string, timeout time.Duration) *Client

type NamedServerDiscover

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

func NewNamedServerDiscover

func NewNamedServerDiscover(clt *Client, opts ...ServerDiscoverOption) *NamedServerDiscover

func (*NamedServerDiscover) Close

func (discover *NamedServerDiscover) Close()

Close discover close

func (*NamedServerDiscover) ElectionServerEndpoint

func (discover *NamedServerDiscover) ElectionServerEndpoint(name string) string

ElectionServerEndpoint 选举服务,根据算法会返回一个最佳的服务器地址

type Server

type Server struct {
	Addr string `json:"addr"`
	Name string `json:"name,omitempty"` // name of the server
	// contains filtered or unexported fields
}

func (*Server) GetAddr

func (svr *Server) GetAddr() string

func (*Server) MarshalBinary

func (svr *Server) MarshalBinary() (data []byte, err error)

func (*Server) UnmarshalBinary

func (svr *Server) UnmarshalBinary(data []byte) error

type ServerDiscoverOption

type ServerDiscoverOption func(svr *Server)

func WithServerNamed

func WithServerNamed(name string) ServerDiscoverOption

func WithServerPerception added in v0.0.4

func WithServerPerception() ServerDiscoverOption

func WithServerPort

func WithServerPort(port int) ServerDiscoverOption

Directories

Path Synopsis
example
customer command
provider command

Jump to

Keyboard shortcuts

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