websocket

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDialPlugin

func NewDialPlugin(rootPath string) drpc.Plugin

NewDialPlugin 创建链接插件

func NewJSONServeHandler

func NewJSONServeHandler(endpoint drpc.Endpoint, handshake func(*websocket.Config, *http.Request) error) http.Handler

NewJSONServeHandler 创建使用json格式编解码的处理器

func NewPbServeHandler

func NewPbServeHandler(endpoint drpc.Endpoint, handshake func(*websocket.Config, *http.Request) error) http.Handler

NewPbServeHandler 创建使用protobuf协议编解码的处理器

func NewServeHandler

func NewServeHandler(endpoint drpc.Endpoint, handshake func(*websocket.Config, *http.Request) error, protoFunc ...proto.ProtoFunc) http.Handler

NewServeHandler 创建处理器

func NewWsProtoFunc

func NewWsProtoFunc(subProto ...proto.ProtoFunc) proto.ProtoFunc

NewWsProtoFunc 创建websocket组件支持的编解码处理器 subProto: 真实的编解码协议,对endpoint来说,它打包和解包是使用了wsproto,实际wsproto是调用了子协议的打包和解包功能

func QueryToken

func QueryToken(tokenKey string, r *http.Request) (token string)

QueryToken 工具函数,方便获取认证用的token

Types

type Acceptor

type Acceptor func(sess drpc.Session) *drpc.Status

Acceptor 检查通过后,接收该链接后,会调用该方法,需要业务自己实现它,传入的参数是会话对象,可以在此做一些初始化操作,

type AfterWebsocketAcceptPlugin

type AfterWebsocketAcceptPlugin interface {
	drpc.Plugin
	AfterAccept(sess drpc.Session, conn *websocket.Conn) *drpc.Status
}

AfterWebsocketAcceptPlugin 在接收到websocket链接之后执行该插件

type BeforeWebsocketHandshakePlugin

type BeforeWebsocketHandshakePlugin interface {
	drpc.Plugin
	BeforeHandshake(r *http.Request) *drpc.Status
}

BeforeWebsocketHandshakePlugin 在websocket握手之前执行该插件

type Checker

type Checker func(r *http.Request) (sessionID string, status *drpc.Status)

Checker 定义检查方法,需要业务自己实现它,检查成功后会返回会话id,该id可以自定义

type Client

type Client struct {
	drpc.Endpoint
}

Client websocket的rpc客户端

func NewClient

func NewClient(rootPath string, cfg drpc.EndpointConfig, globalLeftPlugin ...drpc.Plugin) *Client

NewClient 创建websocket协议的rpc客户端 rootPath: url路径 cfg: drpc框架的配置 globalLeftPlugin: 插件

func (*Client) Dial

func (that *Client) Dial(addr string, protoFunc ...proto.ProtoFunc) (drpc.Session, *drpc.Status)

Dial 链接到服务器

func (*Client) DialJSON

func (that *Client) DialJSON(addr string) (drpc.Session, *drpc.Status)

DialJSON 链接到服务器,并使用json协议编解码传输

func (*Client) DialProtobuf

func (that *Client) DialProtobuf(addr string) (drpc.Session, *drpc.Status)

DialProtobuf 链接到服务器,并使用protobuf协议编解码传输

type HandshakeAuthPlugin

type HandshakeAuthPlugin struct {
	CheckFunc  Checker
	AcceptFunc Acceptor
}

HandshakeAuthPlugin 握手权限检查插件

func NewHandshakeAuthPlugin

func NewHandshakeAuthPlugin(ckFn Checker, apFn Acceptor) *HandshakeAuthPlugin

NewHandshakeAuthPlugin 创建握手权限检查插件

func (*HandshakeAuthPlugin) AfterAccept

func (that *HandshakeAuthPlugin) AfterAccept(sess drpc.Session, conn *websocket.Conn) *drpc.Status

AfterAccept 握手成功后,接受该链接后回调此方法

func (*HandshakeAuthPlugin) BeforeHandshake

func (that *HandshakeAuthPlugin) BeforeHandshake(r *http.Request) *drpc.Status

BeforeHandshake 握手之前回调该方法,可以在此做权限认证的操作

func (*HandshakeAuthPlugin) Name

func (that *HandshakeAuthPlugin) Name() string

type Server

type Server struct {
	drpc.Endpoint
	// contains filtered or unexported fields
}

Server websocket 服务对象

func NewServer

func NewServer(rootPath string, cfg drpc.EndpointConfig, globalLeftPlugin ...drpc.Plugin) *Server

NewServer 创建服务对象 rootPath: 要绑定的url地址 cfg: drpc的配置信息 globalLeftPlugin: drpc的支持的插件

func (*Server) Close

func (that *Server) Close() error

Close 关闭服务

func (*Server) Handle

func (that *Server) Handle(rootPath string, handler http.Handler)

Handle 绑定路由handler

func (*Server) HandleFunc

func (that *Server) HandleFunc(rootPath string, handler func(http.ResponseWriter, *http.Request))

HandleFunc 绑定路由到匿名方法

func (*Server) ListenAndServe

func (that *Server) ListenAndServe(protoFunc ...proto.ProtoFunc) (err error)

ListenAndServe 监听地址端口并提供服务

func (*Server) ListenAndServeJSON

func (that *Server) ListenAndServeJSON() error

ListenAndServeJSON 使用json协议传输数据

func (*Server) ListenAndServeProtobuf

func (that *Server) ListenAndServeProtobuf() error

ListenAndServeProtobuf 使用protobuf协议传输数据

func (*Server) SetHandshake

func (that *Server) SetHandshake(handshake func(*websocket.Config, *http.Request) error)

SetHandshake 设置自定义的握手方法

Directories

Path Synopsis
Package jsonSubProto 实现JSON套接字通信协议的。
Package jsonSubProto 实现JSON套接字通信协议的。
Package pbSubProto 实现PROTOBUF套接字通信协议的。
Package pbSubProto 实现PROTOBUF套接字通信协议的。
pb

Jump to

Keyboard shortcuts

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