Documentation ¶
Index ¶
- Constants
- Variables
- func AcquireTimer(d time.Duration) *time.Timer
- func Logger() *zap.Logger
- func NewConn(conn transport.IServerConn)
- func NewDefaultLogger() *zap.Logger
- func NewRpcError(err error) error
- func ReleaseTimer(t *time.Timer)
- func Serve(host string, rh RequestHandle) error
- func SetInvokeCB(cb func(ctx any, in []byte, err error) error)
- func SugarLogger() *zap.SugaredLogger
- type AsyncInvoker
- type Call
- type Client
- type Codec
- type Conn
- type Decoder
- type DialOption
- type IAsyncInvoker
- type ICall
- type IClient
- type IReply
- type IRequest
- type ISession
- type Item
- type Pending
- type Reply
- type Request
- type RequestHandle
- type RingBuffer
- type Timeout
Constants ¶
View Source
const ( RpcRaw = iota RpcCall RpcAsyncCall RpcTimeout = time.Second * 5 )
View Source
const ( TypeNone = iota TypeRunning TypeStopped )
Client state enum
View Source
const ( TTypeNone = iota TTypeRunning TTypeStopped MaxCheck = 20 )
View Source
const (
BucketNum = 32
)
Variables ¶
View Source
var ( ErrTimeout = errors.New("timeout") ErrDisconnect = errors.New("disconnect") )
Functions ¶
func NewConn ¶
func NewConn(conn transport.IServerConn)
func NewDefaultLogger ¶ added in v1.0.4
func NewRpcError ¶
func ReleaseTimer ¶
func Serve ¶
func Serve(host string, rh RequestHandle) error
func SetInvokeCB ¶
SetInvokeCB Set global asynchronous callback
func SugarLogger ¶ added in v1.0.4
func SugarLogger() *zap.SugaredLogger
Types ¶
type AsyncInvoker ¶
type AsyncInvoker struct {
// contains filtered or unexported fields
}
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
func (*Call) IsAsyncInvoker ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AsyncCallC ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func NewDecoder() *Decoder
type DialOption ¶ added in v1.0.2
type DialOption struct {
DisconnectHandler func(nodeId string)
}
type IAsyncInvoker ¶
func NewAsyncInvoker ¶
type ICall ¶
type ICall interface { Id() uint32 Return() Reply(in []byte, err error) IsAsyncInvoker() bool Invoke(in []byte, err error) error Done() <-chan IReply }
func NewCallWithInvoker ¶
func NewCallWithInvoker(seq uint32, _invoker IAsyncInvoker) ICall
type IClient ¶
type IClient interface { //Shoot is a one-way communication, the sender does not pay attention to the receiver's reply Shoot(out []byte) error // Call performs a unary RPC and returns after the response is received // into replyMsg. // Support users to use context to cancel blocking status or perform timeout operations Call(ctx context.Context, out []byte) ([]byte, error) // AsyncCall the safe way to handle asynchronous callbacks is to package the context, replyMsg, and err // into a message task and send it to the working goroutine to process the message linearly AsyncCall(out []byte, ctx any) error // AsyncCallC the functionality and precautions of AsyncCallC are similar to AsyncCall. // The difference is that AsyncCallC no need to set a global asynchronous callback. AsyncCallC(out []byte, ctx any, cb func(ctx any, in []byte, err error) error) error // Close will close all transport links, causes all subsequent requests to fail, // All Call or asynchronous Call requests in the waiting queue will return and receive the error ErrDisconnect 'rpc err: disconnect' // Close can be called repeatedly Close() }
IClient defines the functions clients need to perform unary and streaming RPCs Support two modes
1: Call 2: Asynchronous Call 3: Shoot
When the transport connection is disconnected, all Call or asynchronous Call requests in the waiting queue will return and receive the error 'rpc err: disconnect'
type IRequest ¶
type IRequest interface { NewReader() packet.IPacket Data() []byte Category() int8 Response(out []byte) error IgnoreRsp() // Return To prevent request resource memory leaks, // you need to explicitly call the Return method to release it. // cannot call Response again later Return() }
IRequest To avoid IRequest resource leakage, IRequest requires the receiver to call Return() to return it to the pool
type Item ¶
type Item[K comparable, V any] struct { // contains filtered or unexported fields }
type RequestHandle ¶
RequestHandle To avoid IRequest resource leakage, IRequest requires the receiver to actively call Return to return it to the pool
type RingBuffer ¶
type RingBuffer[v any] struct { }
type Timeout ¶
type Timeout struct {
// contains filtered or unexported fields
}
func NewTimeoutMgr ¶
Click to show internal directories.
Click to hide internal directories.