rpc

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 17 Imported by: 2

README

rpc

此库弃用,不再维护,建议使用以下package

github.com/zituocn/gow/lib/gb

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIp added in v1.1.0

func GetIp() (string, error)

GetIp return ip address

func GetLocalIP added in v1.1.0

func GetLocalIP() (string, error)

GetLocalIP get local ip address

returns address and error

func ID added in v1.1.0

func ID() string

ID return id

func LocalIPv4s added in v1.1.0

func LocalIPv4s() ([]string, error)

LocalIPv4s return all non-loop back IPv4 addresses

Types

type Client added in v1.1.0

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

Client GRPC Client struct

func NewClient

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

NewClient return grpc Client obj

func (*Client) Conn added in v1.1.0

func (c *Client) Conn() (client *grpc.ClientConn, ctx context.Context, err error)

Conn 直连 return grpc.ClientConn, context.Context, err

func (*Client) Min added in v1.1.0

func (c *Client) Min() (client *grpc.ClientConn, ctx context.Context, err error)

Min 通过etcd发现服务获取grpc连接; 负载均衡 - 最小连接数法; return grpc.ClientConn, context.Context, err

func (*Client) Rand added in v1.1.0

func (c *Client) Rand() (client *grpc.ClientConn, ctx context.Context, err error)

Rand 通过etcd发现服务获取grpc连接; 负载均衡 - 随机法; return grpc.ClientConn, context.Context, err

type ClientArg added in v1.1.0

type ClientArg struct {
	ServerAddr  string // 直连  *必填
	EtcdAddr    string // 使用发现服务 *必填
	ClientName  string
	ServiceName string // *必填
}

ClientArg GRPC Client arg struct

type EtcdCli added in v1.1.0

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

EtcdCli etcd cli struct

func NewEtcdCli added in v1.1.0

func NewEtcdCli(etcdAddr []string) *EtcdCli

NewEtcdCli new etcd cli

func (*EtcdCli) Conn added in v1.1.0

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

Conn return *EtcdCli error

func (*EtcdCli) Delete added in v1.1.0

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

Delete delete key

return error

func (*EtcdCli) DeleteAll added in v1.1.0

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

DeleteAll delete all key by Prefix

returns error

func (*EtcdCli) Get added in v1.1.0

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

Get return *clientv3.GetResponse error

func (*EtcdCli) GetAllKey added in v1.1.0

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

GetAllKey 使用前缀key查询值

func (*EtcdCli) GetHash added in v1.1.0

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

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

func (*EtcdCli) GetMinKey added in v1.1.0

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

GetMinKey 获取被计数最少的key

func (*EtcdCli) GetMinKeyCallBack added in v1.1.0

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

GetMinKeyCallBack 是GetMinKey方法的回调

func (*EtcdCli) GetRandKey added in v1.1.0

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

GetRandKey 使用前缀key查询随机反回一个

func (*EtcdCli) Register added in v1.1.0

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

Register 注册,并创建租约

func (*EtcdCli) SetConnTimeOut added in v1.1.0

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

SetConnTimeOut set etcd conn timeout

func (*EtcdCli) SetTTl added in v1.1.0

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

SetTTl set ttl

func (*EtcdCli) UnRegister added in v1.1.0

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 added in v1.1.0

func (m *Server) OpenRegister() *Server

OpenRegister set isRegister=true

func (*Server) Run

func (m *Server) Run()

Run run rpc server

func (*Server) SetEtcdAddr added in v1.1.0

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

SetEtcdAddr set etcd address

func (*Server) SetName added in v1.1.0

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

SetName set grpc server name

func (*Server) SetPort added in v1.1.0

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

SetPort set grpc port

type ServerArg added in v1.1.0

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

ServerArg GRPC Server Arg struct

func (ServerArg) String added in v1.1.0

func (addr ServerArg) String() string

String ServerArg ip -> string

Jump to

Keyboard shortcuts

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