Documentation
¶
Overview ¶
Package wserver provides building simple websocket server with message push.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRequestIllegal = errors.New("request data illegal")
ErrRequestIllegal describes error when data of the request is unaccepted.
Functions ¶
This section is empty.
Types ¶
type BodyMessage ¶ added in v1.1.0
type BodyMessage struct {
SystemType int `json:"SystemType,string,omitempty"`
}
BodyMessage defines messge body struct sent by client
type Conn ¶
type Conn struct { Conn *websocket.Conn AfterReadFunc func(messageType int, r io.Reader) BeforeCloseFunc func() // contains filtered or unexported fields }
Conn wraps websocket.Conn with Conn. It defines to listen and read data from Conn.
type PushMessage ¶ added in v1.1.0
PushMessage defines message struct send by client to push to each connected websocket client.
type ReceiveMessage ¶ added in v1.1.0
ReceiveMessage defines message struct client send after connect to the server.
type Server ¶
type Server struct { // Address for server to listen on Addr string // Path for websocket request, default "/ws". WSPath string // Path for push message, default "/push". PushPath string StatusPath string LoopInterval int // Upgrader is for upgrade connection to websocket connection using // "github.com/gorilla/websocket". // // If Upgrader is nil, default upgrader will be used. Default upgrader is // set ReadBufferSize and WriteBufferSize to 1024, and CheckOrigin always // returns true. Upgrader *websocket.Upgrader // Check token if it's valid and return userID. If token is valid, userID // must be returned and ok should be true. Otherwise ok should be false. AuthToken func(token string) (userID string, ok bool) // Authorize push request. Message will be sent if it returns true, // otherwise the request will be discarded. Default nil and push request // will always be accepted. PushAuth func(r *http.Request) bool StatusAuth func(r *http.Request) bool PushMethod func(params map[string]string) ([]byte, error) // contains filtered or unexported fields }
Server defines parameters for running websocket server.
func (*Server) Drop ¶ added in v1.1.0
Drop find connections by userID and event, then close them. The userID can't be empty. The event is ignored if it's empty.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address and handle websocket request.