grpc

package
v0.0.0-...-67d91c4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 17 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(dis ClientArg) (*client, error)

NewDiscovery 创建发现服务

Types

type ClientArg

type ClientArg struct {
	ServiceAddr string
	EtcdAddr    string
	ClientName  string
	ServiceName string
	ReqFuncName string
	OpenLog     bool
}

DiscoveryArg 创建发现服务对象参数

type EtcdCli

type EtcdCli struct {
	EtcdAddr []string
	// contains filtered or unexported fields
}

func NewEtcdCli

func NewEtcdCli(etcdAddr []string) *EtcdCli

func (*EtcdCli) Conn

func (etcdCil *EtcdCli) Conn() (*EtcdCli, error)

Conn 连接ETCD

func (*EtcdCli) Delete

func (etcdCil *EtcdCli) Delete(key string) error

Delete

func (*EtcdCli) DeleteAll

func (etcdCil *EtcdCli) DeleteAll(key string) error

Delete All

func (*EtcdCli) Get

func (etcdCil *EtcdCli) Get(key string) (*clientv3.GetResponse, error)

Get 获取

func (*EtcdCli) GetAllKey

func (etcdCil *EtcdCli) GetAllKey(key string) ([]string, error)

GetAllKey 模糊key查询对应的所有key

func (*EtcdCli) GetHash

func (etcdCil *EtcdCli) GetHash(key, h string)

GetHash 通过传入h把value进行hash,然后后返回 h : 用于计算hash的值

func (*EtcdCli) GetMinKey

func (etcdCil *EtcdCli) GetMinKey(key string) (string, error)

GetMinKey 轮询获取key, 前置条件: value是用于计数的 key 是模糊key, 如 /A/

func (*EtcdCli) GetMinKeyCallBack

func (etcdCil *EtcdCli) GetMinKeyCallBack(key string) error

GetMinKeyCallBack 与 EtcdCli.GetMinKey 配合使用客户端连接成功后调用

func (*EtcdCli) GetRandKey

func (etcdCil *EtcdCli) GetRandKey(key string) (string, error)

GetRandKey 模糊key查询随机反回一个key

func (*EtcdCli) Register

func (etcdCil *EtcdCli) Register(key, value string) error

Register 注册,并创建租约

func (*EtcdCli) SetConnTimeOut

func (etcdCil *EtcdCli) SetConnTimeOut(timeOut int) *EtcdCli

SetConnTimeOut 设置连接etcd的timeout

func (*EtcdCli) SetTTl

func (etcdCil *EtcdCli) SetTTl(ttl int) *EtcdCli

SetTTl 设置ttl

func (*EtcdCli) UnRegister

func (etcdCil *EtcdCli) UnRegister(key string) error

UnRegister 解除注册

type Server

type Server struct {
	Listener net.Listener
	Server   *grpc.Server
	Port     int    // 端口
	Name     string // 服务昵称
	EtcdAddr []string
	// contains filtered or unexported fields
}

Server GRPC Server struct

func NewServer

func NewServer(grpcAddr ServerArg) (server *Server, err error)

NewServer returns a new server

func (*Server) OpenRegister

func (m *Server) OpenRegister() *Server

func (*Server) Run

func (m *Server) Run()

Run run rpc server

func (*Server) SetEtcdAddr

func (m *Server) SetEtcdAddr(etcdAddr string) *Server

func (*Server) SetName

func (m *Server) SetName(name string) *Server

func (*Server) SetPort

func (m *Server) SetPort(port int) *Server

type ServerArg

type ServerArg struct {
	IP       string
	Port     int
	Name     string
	EtcdAddr string // 多个地址必须使用","分开; 如: 192.168.0.1:2379,192.168.0.2:2379
	Register bool   // 是否启用服务注册
}

GrpcServerArg grpc服务端参数

func (ServerArg) String

func (addr ServerArg) String() string

Jump to

Keyboard shortcuts

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