rpc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(data Data) ([]byte, error)

Encode data

Types

type Client

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

Client struct

func NewClient

func NewClient(conn net.Conn) *Client

NewClient create a new client

func (*Client) Call

func (c *Client) Call(name string, fptr interface{})

Call transforms a function prototype into a function

func (*Client) GetConn

func (c *Client) GetConn() net.Conn

GetConn returns the connection to server

type Config

type Config struct {
	MaxOpenCount  int
	MaxIdleCount  int
	RpcServerAddr string
}

Config 连接池配置

type ConnPool

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

ConnPool 连接池

func NewPool

func NewPool(config *Config) *ConnPool

NewPool 创建连接吃

func (*ConnPool) Achieve

func (pool *ConnPool) Achieve(ctx context.Context) (permission Permission, err error)

Achieve 获取连接

func (*ConnPool) Exec

func (pool *ConnPool) Exec(ctx context.Context, handle func(client *Client)) error

Exec 执行函数,返回结果

func (*ConnPool) Release

func (pool *ConnPool) Release(client *Client, ctx context.Context) (result bool, err error)

Release 释放连接

func (*ConnPool) Stat

func (pool *ConnPool) Stat() Stat

Stat 获取连接池状态

type Data

type Data struct {
	Name string        // service name
	Args []interface{} // request's or response's body
	Err  string        // remote server error
}

Data presents the pb transported between server and client

func Decode

func Decode(b []byte) (Data, error)

Decode data

type NextConnIndex

type NextConnIndex struct {
	Index int
}

NextConnIndex 下一个连接的标识

type Permission

type Permission struct {
	NextConnIndex
	RpcCli      *Client
	CreateAt    time.Time
	MaxLifeTime time.Duration
}

Permission 权限,包装连接

type Server

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

Server struct

func NewServer

func NewServer(addr string) *Server

NewServer create a new server

func (*Server) Register

func (s *Server) Register(name string, f interface{})

Register register a function via name

func (*Server) Run

func (s *Server) Run()

Run start server

type Stat

type Stat struct {
	OpenCount int
	IdleCount int
	WaitCount int
}

Stat 连接池状态

type Transport

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

Transport struct

func NewTransport

func NewTransport(conn net.Conn) *Transport

NewTransport creates a transport

func (*Transport) Receive

func (t *Transport) Receive() (Data, error)

Receive data

func (*Transport) Send

func (t *Transport) Send(req Data) error

Send data

Directories

Path Synopsis
demo

Jump to

Keyboard shortcuts

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