rpc

package
v0.0.0-...-3aae54d Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockClient

func NewMockClient(ctx context.Context, fun interface{}, s interface{}) (c mockClient, err error)

NewClient fun: pb.RegisterHelloServer(s *grpc.Server, srv HelloServer)

Types

type CliMethod

type CliMethod struct {
	Name   string
	CallID uint16
	// contains filtered or unexported fields
}

func (CliMethod) FuncName

func (m CliMethod) FuncName() string

func (CliMethod) NewReq

func (m CliMethod) NewReq() codec.Msg

func (CliMethod) NewResp

func (m CliMethod) NewResp() codec.Msg

func (CliMethod) ReqType

func (m CliMethod) ReqType() reflect.Type

func (CliMethod) RespType

func (m CliMethod) RespType() reflect.Type

func (CliMethod) SvcInvoke

func (m CliMethod) SvcInvoke(ctx context.Context, req codec.Msg) (resp codec.Msg, err error)

type CliParam

type CliParam struct {
	Ctx    context.Context
	Method string
	Req    codec.Msg
	Resp   codec.Msg
	Err    error
	// contains filtered or unexported fields
}

func (*CliParam) Next

func (p *CliParam) Next()

type Client

type Client struct {
	*codec.Codec
	// contains filtered or unexported fields
}

func StartClient

func StartClient(ctx context.Context, rwc io.ReadWriteCloser, fRegisters ...interface{}) (c Client, err error)

StartClient fRegister: pb.RegisterHelloServer(s *grpc.Server, srv HelloServer)

func (Client) Close

func (c Client) Close(ctx context.Context) (err error)

func (Client) Invoke

func (c Client) Invoke(ctx context.Context, method string, req codec.Msg, resp codec.Msg) (err error)

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, method string) (stream *codec.Stream, err error)

Stream 流式调用

func (*Client) StreamAsync

func (c *Client) StreamAsync(ctx context.Context, method string) (stream *codec.Stream, err error)

StreamAsync 不等对方返回

func (*Client) Upgrade

func (c *Client) Upgrade(ctx context.Context, method string, req, res codec.Msg) (upgrade *codec.Upgrade, err error)

Stream 流式调用

func (*Client) Use

func (rpc *Client) Use(middleware ...MiddlewareReqFunc)

type LogidKey

type LogidKey = codec.LogidKey

type MiddlewareReqFunc

type MiddlewareReqFunc = func(*CliParam)

type MiddlewareRespFunc

type MiddlewareRespFunc = func(*SvcParam)

type Peer

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

func NewPeer

func NewPeer(ctx context.Context, svc interface{}, fRegisters ...interface{}) (rpc Peer, err error)

ctx 里 PassthroughKey{} 的 []string 类型; ctx透传value 的key列表, 传value总和长度不能超过65532 fRegisters: 自己需要实现的server接口、需要请求对方的client接口注册函数.

func StartPeer

func StartPeer(ctx context.Context, rwc io.ReadWriteCloser, svc interface{}, fRegisters ...interface{}) (rpc Peer, err error)

func (*Peer) ClientPassKey

func (rpc *Peer) ClientPassKey(cliPassKeys ...string)

value 必须是 []string 类型的才会透传到 server 端

func (*Peer) ClientUse

func (rpc *Peer) ClientUse(middleware ...MiddlewareReqFunc)

func (Peer) Clone

func (rpc Peer) Clone(ctx context.Context, rwc io.ReadWriteCloser, svc interface{}) (out Peer, err error)

func (Peer) Close

func (rpc Peer) Close(ctx context.Context) (err error)

func (*Peer) Conn

func (rpc *Peer) Conn(ctx context.Context, rwc io.ReadWriteCloser) (err error)

func (Peer) Done

func (rpc Peer) Done() <-chan struct{}

func (Peer) IsClosed

func (rpc Peer) IsClosed() bool

func (*Peer) ServiceUse

func (rpc *Peer) ServiceUse(middleware ...MiddlewareRespFunc)

type Service

type Service struct {
	*codec.Codec
	// contains filtered or unexported fields
}

func StartService

func StartService(ctx context.Context, rwc io.ReadWriteCloser, svc interface{}, fRegisters ...interface{}) (s Service, err error)

StartService fRegister: pb.RegisterHelloService, svc: implementation

func (Service) AllInterfaces

func (s Service) AllInterfaces() (is []SvcMethod)

func (Service) Call

func (s Service) Call(ctx context.Context, methodIdx uint32, req unsafe.Pointer) (resp unsafe.Pointer, err error)

func (Service) CloneMethods

func (s Service) CloneMethods(svc interface{}) []codec.Method

func (Service) Close

func (c Service) Close(ctx context.Context) (err error)

func (Service) MethodIdx

func (s Service) MethodIdx(method string) (idx uint32, exist bool)

func (Service) Methods

func (s Service) Methods() []codec.Method

func (*Service) Use

func (rpc *Service) Use(middleware ...MiddlewareRespFunc)

type SvcMethod

type SvcMethod struct {
	CliMethod
	Func       func(unsafe.Pointer, context.Context, unsafe.Pointer) (unsafe.Pointer, error)
	SvcPointer unsafe.Pointer
}

func (SvcMethod) SvcInvoke

func (m SvcMethod) SvcInvoke(ctx context.Context, req codec.Msg) (resp codec.Msg, err error)

type SvcParam

type SvcParam struct {
	Ctx    context.Context
	Method string
	Req    codec.Msg
	Resp   *codec.Msg
	Err    error
	// contains filtered or unexported fields
}

func (*SvcParam) Next

func (p *SvcParam) Next()

type WrapSvcMethod

type WrapSvcMethod struct {
	SvcMethod
	// contains filtered or unexported fields
}

func (WrapSvcMethod) SvcInvoke

func (m WrapSvcMethod) SvcInvoke(ctx context.Context, req codec.Msg) (resp codec.Msg, err error)

Jump to

Keyboard shortcuts

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