Documentation ¶
Overview ¶
Package websocket is an extension package that makes the eRPC framework compatible with websocket protocol as specified in RFC 6455.
Copyright 2018 HenryLee. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 HenryLee. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func NewDialPlugin(rootPath string) erpc.Plugin
- func NewJSONServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler
- func NewPbServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler
- func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error, ...) http.Handler
- func NewWsProtoFunc(subProto ...erpc.ProtoFunc) erpc.ProtoFunc
- func QueryToken(tokenKey string, r *http.Request) (token string)
- type Acceptor
- type Checker
- type Client
- type HandshakeAuthPlugin
- type PostWebsocketAcceptPlugin
- type PreWebsocketHandshakePlugin
- type Server
- func (srv *Server) Close() error
- func (srv *Server) Handle(rootPath string, handler http.Handler)
- func (srv *Server) HandleFunc(rootPath string, handler func(http.ResponseWriter, *http.Request))
- func (srv *Server) ListenAndServe(protoFunc ...erpc.ProtoFunc) (err error)
- func (srv *Server) ListenAndServeJSON() error
- func (srv *Server) ListenAndServeProtobuf() error
- func (srv *Server) SetHandshake(handshake func(*ws.Config, *http.Request) error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDialPlugin ¶
func NewDialPlugin(rootPath string) erpc.Plugin
NewDialPlugin creates a websocket plugin for client.
func NewJSONServeHandler ¶
func NewJSONServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler
NewJSONServeHandler creates a websocket json handler.
func NewPbServeHandler ¶
func NewPbServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error) http.Handler
NewPbServeHandler creates a websocket protobuf handler.
func NewServeHandler ¶
func NewServeHandler(peer erpc.Peer, handshake func(*ws.Config, *http.Request) error, protoFunc ...erpc.ProtoFunc) http.Handler
NewServeHandler creates a websocket handler.
func NewWsProtoFunc ¶
func NewWsProtoFunc(subProto ...erpc.ProtoFunc) erpc.ProtoFunc
NewWsProtoFunc wraps a protocol to a new websocket protocol.
Types ¶
type Acceptor ¶
type Acceptor func(sess erpc.Session) *erpc.Status
Acceptor provide authenticated erpc.Session you can get the sessionID that your return by Checker()
type Checker ¶
Checker deal with http.Request and your authenticate logic, the a sessionID returned will used by erpc.Session.SetID(), if auth succeeded.
type Client ¶
type Client struct {
erpc.Peer
}
Client a websocket client
func (*Client) DialProtobuf ¶
DialProtobuf connects with the Protobuf protocol.
type HandshakeAuthPlugin ¶
func NewHandshakeAuthPlugin ¶
func NewHandshakeAuthPlugin(ckFn Checker, apFn Acceptor) *HandshakeAuthPlugin
NewHandshakeAuthPlugin creates a handshake auth plugin for server.
func (*HandshakeAuthPlugin) Name ¶
func (p *HandshakeAuthPlugin) Name() string
func (*HandshakeAuthPlugin) PostAccept ¶
func (p *HandshakeAuthPlugin) PostAccept(sess erpc.Session, conn *ws.Conn) *erpc.Status
func (*HandshakeAuthPlugin) PreHandshake ¶
func (p *HandshakeAuthPlugin) PreHandshake(r *http.Request) *erpc.Status
type PostWebsocketAcceptPlugin ¶
type PostWebsocketAcceptPlugin interface {
erpc.Plugin
PostAccept(sess erpc.Session, conn *ws.Conn) *erpc.Status
}
PreHandshake executes the PostWebsocketAcceptPlugin after websocket accepting connection
type PreWebsocketHandshakePlugin ¶
type PreWebsocketHandshakePlugin interface {
erpc.Plugin
PreHandshake(r *http.Request) *erpc.Status
}
PreHandshake executes the PreWebsocketHandshakePlugins before websocket handshake,
type Server ¶
type Server struct { erpc.Peer // contains filtered or unexported fields }
Server a websocket server
func (*Server) Handle ¶
Handle registers the handler for the given rootPath. If a handler already exists for rootPath, Handle panics.
func (*Server) HandleFunc ¶
HandleFunc registers the handler function for the given rootPath.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives.
The handler is typically nil, in which case the DefaultServeMux is used.
ListenAndServe always returns a non-nil error.
If protoFunc is empty, JSON is used by default.
func (*Server) ListenAndServeJSON ¶
ListenAndServeJSON listen and serve with the JSON protocol.
func (*Server) ListenAndServeProtobuf ¶
ListenAndServeProtobuf listen and serve with the Protobuf protocol.
Directories ¶
Path | Synopsis |
---|---|
Package jsonSubProto is implemented JSON socket communication protocol.
|
Package jsonSubProto is implemented JSON socket communication protocol. |
Package pbSubProto is implemented PROTOBUF socket communication protocol.
|
Package pbSubProto is implemented PROTOBUF socket communication protocol. |
Package websocket implements a client and server for the WebSocket protocol as specified in RFC 6455.
|
Package websocket implements a client and server for the WebSocket protocol as specified in RFC 6455. |