api

package
v0.0.6-beta Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type BaseTransportClient

type BaseTransportClient struct {
	EventChan chan ConnectEvent
	Watchers  []ConnectEventListener
	Filters   []func(req *ServerRequest)
	CancelFs  []context.CancelFunc
	// contains filtered or unexported fields
}

func NewBaseClient

func NewBaseClient() *BaseTransportClient

func (*BaseTransportClient) AddChain

func (btc *BaseTransportClient) AddChain(filter func(req *ServerRequest))

func (*BaseTransportClient) AddWatcher

func (btc *BaseTransportClient) AddWatcher(watcher ConnectEventListener)

func (*BaseTransportClient) DoFilter

func (btc *BaseTransportClient) DoFilter(req *ServerRequest)

type ChannelHandler

type ChannelHandler func(cxt context.Context, rpcCtx RpcServerContext)

type ClientOption

type ClientOption struct {
	ConnectType ConnectType
	OpenTSL     bool
}

type ClientOptions

type ClientOptions func(opt *ClientOption)

type ConnectEvent

type ConnectEvent struct {
	EventType ConnectEventType
	Conn      net.Conn
}

type ConnectEventListener

type ConnectEventListener func(eventType ConnectEventType, con net.Conn)

type ConnectEventType

type ConnectEventType int8
const (
	ConnectEventForConnected ConnectEventType = iota
	ConnectEventForDisConnected
)

func (ConnectEventType) String

func (i ConnectEventType) String() string

type ConnectType

type ConnectType string

ConnectType 连接类型

const (
	ConnectTypeRSocket ConnectType = "RSocket"
	ConnectWebSocket   ConnectType = "WebSocket"
	ConnectGrpc        ConnectType = "gRPC"
)

type DefaultEndpointRepository

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

EndpointRepository 管理实例的仓库

func (*DefaultEndpointRepository) Put

func (erp *DefaultEndpointRepository) Put(name string, endpoint Endpoint)

Put 为某个服务添加一个服务实例

func (*DefaultEndpointRepository) Remove

func (erp *DefaultEndpointRepository) Remove(name string, endpoint Endpoint)

Remove 从某个服务中移除实例

func (*DefaultEndpointRepository) SelectOne

func (erp *DefaultEndpointRepository) SelectOne(name string) (bool, Endpoint)

SelectOne 选择一个服务的实例进行随机访问

type Dispatcher

type Dispatcher struct {
	Label string
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher(label string) Dispatcher

func (*Dispatcher) FindChannelHandler

func (r *Dispatcher) FindChannelHandler(key string) ChannelHandler

func (*Dispatcher) FindSimpleHandler

func (r *Dispatcher) FindSimpleHandler(key string) SimpleHandler

func (*Dispatcher) RegisterChannelHandler

func (r *Dispatcher) RegisterChannelHandler(key string, handler ChannelHandler) bool

func (*Dispatcher) RegisterSimpleHandler

func (r *Dispatcher) RegisterSimpleHandler(key string, handler SimpleHandler) bool

type Endpoint

type Endpoint struct {
	Key  string
	Host string
	Port int32
	// contains filtered or unexported fields
}

Endpoint 实例的链接信息

func (Endpoint) GetKey

func (e Endpoint) GetKey() string

type EndpointRepository

type EndpointRepository interface {
	//SelectOne 选择一个服务的实例进行随机访问
	SelectOne(name string) (bool, Endpoint)
	//Put 为某个服务添加一个服务实例
	Put(name string, endpoint Endpoint)
	//Remove 从某个服务中移除实例
	Remove(name string, endpoint Endpoint)
}

func NewDefaultEndpointRepository

func NewDefaultEndpointRepository() EndpointRepository

NewDefaultEndpointRepository 创建一个默认的 EndpointRepository

type ProxyConn

type ProxyConn struct {
	Target  net.Conn
	OnClose func(conn net.Conn)
}

func (*ProxyConn) Close

func (c *ProxyConn) Close() error

func (*ProxyConn) LocalAddr

func (c *ProxyConn) LocalAddr() net.Addr

func (*ProxyConn) Read

func (c *ProxyConn) Read(b []byte) (n int, err error)

func (*ProxyConn) RemoteAddr

func (c *ProxyConn) RemoteAddr() net.Addr

func (*ProxyConn) SetDeadline

func (c *ProxyConn) SetDeadline(t time.Time) error

func (*ProxyConn) SetReadDeadline

func (c *ProxyConn) SetReadDeadline(t time.Time) error

func (*ProxyConn) SetWriteDeadline

func (c *ProxyConn) SetWriteDeadline(t time.Time) error

func (*ProxyConn) Write

func (c *ProxyConn) Write(b []byte) (n int, err error)

type RpcClientContext

type RpcClientContext interface {
	io.Closer

	Send(resp *ServerRequest)

	Receive() (<-chan *ServerResponse, <-chan error)
}

RpcClientContext Client端对于一个请求的发送

type RpcServerContext

type RpcServerContext interface {
	io.Closer

	GetReq() *ServerRequest

	Send(resp *ServerResponse) error
}

RpcServerContext Server端对于一个请求的上下文

type ServerOption

type ServerOption struct {
	ConnectType ConnectType
	Label       string
	Port        int32
	OpenTSL     bool
}

type ServerOptions

type ServerOptions func(opt *ServerOption)

type ServerRequest

type ServerRequest struct {
	FunName   string            `protobuf:"bytes,1,opt,name=FunName,proto3" json:"FunName,omitempty"`
	Body      *anypb.Any        `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
	RequestId string            `protobuf:"bytes,3,opt,name=requestId,proto3" json:"requestId,omitempty"`
	Header    map[string]string `` /* 153-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*ServerRequest) Descriptor deprecated

func (*ServerRequest) Descriptor() ([]byte, []int)

Deprecated: Use ServerRequest.ProtoReflect.Descriptor instead.

func (*ServerRequest) GetBody

func (x *ServerRequest) GetBody() *anypb.Any

func (*ServerRequest) GetFunName

func (x *ServerRequest) GetFunName() string

func (*ServerRequest) GetHeader

func (x *ServerRequest) GetHeader() map[string]string

func (*ServerRequest) GetRequestId

func (x *ServerRequest) GetRequestId() string

func (*ServerRequest) ProtoMessage

func (*ServerRequest) ProtoMessage()

func (*ServerRequest) ProtoReflect

func (x *ServerRequest) ProtoReflect() protoreflect.Message

func (*ServerRequest) Reset

func (x *ServerRequest) Reset()

func (*ServerRequest) String

func (x *ServerRequest) String() string

type ServerResponse

type ServerResponse struct {
	FunName   string            `protobuf:"bytes,1,opt,name=FunName,proto3" json:"FunName,omitempty"`
	RequestId string            `protobuf:"bytes,2,opt,name=requestId,proto3" json:"requestId,omitempty"`
	Header    map[string]string `` /* 153-byte string literal not displayed */
	Code      int32             `protobuf:"varint,3,opt,name=code,proto3" json:"code,omitempty"`
	Body      *anypb.Any        `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"`
	Msg       string            `protobuf:"bytes,6,opt,name=msg,proto3" json:"msg,omitempty"`
	// contains filtered or unexported fields
}

func (*ServerResponse) Descriptor deprecated

func (*ServerResponse) Descriptor() ([]byte, []int)

Deprecated: Use ServerResponse.ProtoReflect.Descriptor instead.

func (*ServerResponse) GetBody

func (x *ServerResponse) GetBody() *anypb.Any

func (*ServerResponse) GetCode

func (x *ServerResponse) GetCode() int32

func (*ServerResponse) GetFunName

func (x *ServerResponse) GetFunName() string

func (*ServerResponse) GetHeader

func (x *ServerResponse) GetHeader() map[string]string

func (*ServerResponse) GetMsg

func (x *ServerResponse) GetMsg() string

func (*ServerResponse) GetRequestId

func (x *ServerResponse) GetRequestId() string

func (*ServerResponse) ProtoMessage

func (*ServerResponse) ProtoMessage()

func (*ServerResponse) ProtoReflect

func (x *ServerResponse) ProtoReflect() protoreflect.Message

func (*ServerResponse) Reset

func (x *ServerResponse) Reset()

func (*ServerResponse) String

func (x *ServerResponse) String() string

type SimpleHandler

type SimpleHandler func(cxt context.Context, rpcCtx RpcServerContext)

type TransportClient

type TransportClient interface {
	//RegisterConnectEventWatcher 客户端监听和服务端的会话的状态
	RegisterConnectEventWatcher(watcher func(eventType ConnectEventType, conn net.Conn))
	//CheckConnection 检查链接
	CheckConnection(endpoint Endpoint) (bool, error)
	//AddChain 添加请求处理链
	AddChain(filter func(req *ServerRequest))
	//Request 发起 request-response 请求
	Request(ctx context.Context, endpoint Endpoint, req *ServerRequest) (*ServerResponse, error)
	//RequestChannel 发起 request-channel 请求
	RequestChannel(ctx context.Context, endpoint Endpoint) (RpcClientContext, error)
	//Close 关闭客户端
	Close() error
}

TransportClient 客户端调用接口

type TransportServer

type TransportServer interface {
	//AddConnectEventListener 服务端的监听和客户端的会话的状态
	AddConnectEventListener(listener ConnectEventListener)
	//RemoveConnectEventListener
	RemoveConnectEventListener(listener ConnectEventListener)
	//RegisterSimpleHandler 注册一个 Request-Response的Server端处理者,名称为name
	RegisterSimpleHandler(funName string, handler SimpleHandler)
	//RegisterChannelHandler 注册一个 Request-Channel的Server端处理者,名称为name
	RegisterChannelHandler(funName string, handler ChannelHandler)
}

TransportServer 服务端接口

type UserCall

type UserCall func(resp *ServerResponse, err error)

Jump to

Keyboard shortcuts

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