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
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultHeartbeatDuration 心跳消息发送时间间隔,连接在超过这个时间没有收发消息,就会发送心跳消息 DefaultHeartbeatDuration = 1 * time.Minute // DefaultHeartbeatTimeout 心跳消息超时时间,默认为心跳消息发送时间间隔的3倍 DefaultHeartbeatTimeout = 3 * DefaultHeartbeatDuration // MaxMessageSize 客户端消息最大长度,默认64KB MaxMessageSize = 64 * 1024 )
var ErrDenyByAuthorizer = errors.New("deny by authorizer")
ErrDenyByAuthorizer 身份验证未通过
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 NewQUICServer ¶
func NewQUICServer(listenAddr string, tlsConfig *tls.Config, quicConfig *quic.Config) Transporter
NewQUICServer 构造函数