rpc

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 9 Imported by: 0

README

gitub.com/gkzy/gow/lib/rpc

server

// InitRPCServer 
func InitRPCServer(){
    g,err:=rpc.NewServer(10001)
    if err!=nil{
        panic(err)
    }
    handler(g.Server)
    g.Run()
}

// handler register struct
func handler(g *rpc.Server){

}

client
client,err:=rpc.NewClient("192.168.0.100",10001)
if err!=nil{
        panic(err)
}
...

Documentation

Index

Constants

View Source
const (
	// PoolModeStrict 在实际创建连接数达上限后,池子中没有连接时不会新建连接
	PoolModeStrict = iota

	// PoolModeLoose 在实际创建连接数达上限后,池子中没有连接时会新建连接
	PoolModeLoose
)

Variables

View Source
var (
	// ErrorOption
	ErrorOption = "option error"
	// ErrorPoolInit 连接p池初始化出错
	ErrorPoolInit = "pool init error"
	//ErrorGetTimeout 获取连接超时
	ErrorGetTimeout = "getting connection client timeout from pool"
	//ErrorDialConn 创建连接时发生错误
	ErrorDialConn = "dialing connection error"

	// ErrorPoolIsClosed 连接池已关闭
	ErrorPoolIsClosed = "pool is closed"
)

Functions

func NewClient

func NewClient(serverAddr string, serverPort int) (client *grpc.ClientConn, err error)

NewClient 返回rpc客户端

serverAddr:服务端地址
serverPort:服务端Port

Types

type Client added in v0.4.3

type Client struct {
	*grpc.ClientConn
	// contains filtered or unexported fields
}

Client grpc client

func (*Client) Close added in v0.4.3

func (client *Client) Close()

Close close conn

func (*Client) Destroy added in v0.4.3

func (client *Client) Destroy()

Destroy destroy conn

func (*Client) TimeInit added in v0.4.3

func (client *Client) TimeInit() time.Time

TimeInit 连的创建时间

func (*Client) TimeUsed added in v0.4.3

func (client *Client) TimeUsed() time.Time

TimeUsed 连接上一次的使用时间

type Factor added in v0.4.3

type Factor func() (*grpc.ClientConn, error)

Factor factor func

type Option added in v0.4.3

type Option struct {
	// func() (*grpc.ClientConn, error)
	Factor Factor

	//Init init 连接数
	Init int32

	//Cap 连接上限
	Cap int32

	//IdleDur
	IdleDur time.Duration

	// MaxLifeDur
	MaxLifeDur time.Duration

	// Timeout pool关闭时
	Timeout time.Duration

	// 模式
	Mode int
}

Option pool param option

type Pool added in v0.4.3

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

Pool 连接池

func DefaultPool added in v0.4.3

func DefaultPool(factor Factor, init, cap int32) (*Pool, error)

DefaultPool return a default pool

func NewPool added in v0.4.3

func NewPool(option *Option) (*Pool, error)

NewPool return a new pool

need option

func (*Pool) Close added in v0.4.3

func (pool *Pool) Close()

func (*Pool) ConnCnt added in v0.4.3

func (pool *Pool) ConnCnt() int32

ConnCnt 实际连接数

func (*Pool) Get added in v0.4.3

func (pool *Pool) Get(ctx context.Context) (*Client, error)

Get 从连接池取出一个链接

func (*Pool) IsClose added in v0.4.3

func (pool *Pool) IsClose() bool

func (*Pool) Size added in v0.4.3

func (pool *Pool) Size() int

Size return pool client size

type Server

type Server struct {
	Listener net.Listener
	Server   *grpc.Server
	Port     int //端口
}

Server GRPCServer

func NewServer

func NewServer(port int) (server *Server, err error)

NewServer init一个新的服务

func (*Server) Run

func (m *Server) Run()

Run run rpc server

Jump to

Keyboard shortcuts

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