Documentation ¶
Index ¶
- Variables
- type Authorizer
- type CallOption
- type Client
- type ConnectInterceptor
- type DisconnectInterceptor
- type Option
- func WithAuthorizer(authorizer Authorizer) Option
- func WithConnectInterceptor(interceptor ConnectInterceptor) Option
- func WithDisconnectInterceptor(interceptor DisconnectInterceptor) Option
- func WithEventBus(bus *event.Bus) Option
- func WithMulticast(multicast multicast.Subscriber) Option
- func WithRegistry(registry *cluster.Registry) Option
- func WithRequestInterceptor(interceptor RequestInterceptor) Option
- func WithRequestLogger(logger logger.Logger) Option
- func WithTransporter(transporter Transporter) Option
- type Proxy
- type RequestInterceptor
- type Session
- type Transporter
- func BindQUICServer(conn net.PacketConn, tlsConfig *tls.Config, quicConfig *quic.Config) Transporter
- func BindTCPServer(listener net.Listener) Transporter
- func BindWSServer(listener net.Listener, urlPath string) Transporter
- func NewQUICServer(listenAddr string, tlsConfig *tls.Config, quicConfig *quic.Config) Transporter
- func NewTCPServer(listenAddr string) Transporter
- func NewWSServer(listenAddr string, urlPath string) Transporter
Constants ¶
This section is empty.
Variables ¶
var ( // KeepaliveInterval 网络连接保持活跃时间,默认1分钟 // // 客户端在没有业务消息的情况下,需要定时向服务器端发送心跳消息 // 服务器端如果检测到客户端连接超过这个时间还没有任何读写,就会认为此连接已断线,会触发主动断线操作 KeepaliveInterval = 1 * time.Minute // MaxMessageSize 客户端消息最大长度,默认64KB MaxMessageSize = 64 * 1024 )
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
Authorizer 身份认证
返回的metadata会在此连接的所有grpc request中携带 返回的userID会作为会话唯一标识使用,也会被自动加入到metadata中 如果返回ok为false,会直接关闭连接 因此如果验证不通过之类的错误,需要在这个函数里面自行处理
type CallOption ¶
CallOption 调用选项
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 网关客户端,用于测试及演示
func NewQUICClient ¶
NewQUICClient 创建QUIC客户端
func (*Client) Call ¶
func (c *Client) Call(serviceCode int32, method string, arg proto.Message, options ...CallOption) error
Call 发起远程调用
func (*Client) OnReceive ¶
OnReceive 注册消息处理器
Example:
client.OnReceive(gateway.ServiceCode, int32(gatewaypb.Protocol_RPC_ERROR), func(requestID uint32, msg *gatewaypb.RPCError) { // ... })
func (*Client) SetDefaultHandler ¶
SetDefaultHandler 设置默认消息处理器
type ConnectInterceptor ¶
ConnectInterceptor 在连接创建之后执行自定义操作,返回错误会中断连接
type DisconnectInterceptor ¶
DisconnectInterceptor 在连接断开前执行自定操作
type Option ¶
type Option func(p *Proxy)
Option 网关配置选项
func WithConnectInterceptor ¶
func WithConnectInterceptor(interceptor ConnectInterceptor) Option
WithConnectInterceptor 设置连接拦截器
func WithDisconnectInterceptor ¶
func WithDisconnectInterceptor(interceptor DisconnectInterceptor) Option
WithDisconnectInterceptor 设置断开连接拦截器
func WithRequestInterceptor ¶
func WithRequestInterceptor(interceptor RequestInterceptor) Option
WithRequestInterceptor 设置请求拦截器
func WithRequestLogger ¶
WithRequestLogger 设置请求日志记录器
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy 客户端会话运行环境
func (*Proxy) CompleteNodeEntry ¶
CompleteNodeEntry 补全节点信息
func (*Proxy) NewGRPCService ¶
func (p *Proxy) NewGRPCService() nh.GatewayServer
NewGRPCService 网关管理服务
type RequestInterceptor ¶
type RequestInterceptor func(ctx context.Context, sess Session, req *nh.Request) (pass bool, err error)
RequestInterceptor 请求拦截器
每次收到客户端请求都会执行,return pass=false会中断当次请求
type Session ¶
type Session interface { ID() string SetID(string) SetMetadata(metadata.MD) MetadataCopy() metadata.MD Recv(*nh.Request) error Send(*nh.Reply) error LocalAddr() string RemoteAddr() string LastRWTime() time.Time Close() error LogValue() slog.Value }
Session 连接会话
type Transporter ¶
type Transporter interface { CompleteNodeEntry(entry *cluster.NodeEntry) Serve(ctx context.Context) (chan Session, error) Shutdown(ctx context.Context) error }
Transporter 网关传输层接口
func BindQUICServer ¶
func BindQUICServer(conn net.PacketConn, tlsConfig *tls.Config, quicConfig *quic.Config) Transporter
BindQUICServer 绑定QUIC服务器
func BindWSServer ¶
func BindWSServer(listener net.Listener, urlPath string) Transporter
BindWSServer 绑定websocket服务器
func NewQUICServer ¶
func NewQUICServer(listenAddr string, tlsConfig *tls.Config, quicConfig *quic.Config) Transporter
NewQUICServer 构造函数