wslt

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: Apache-2.0 Imports: 16 Imported by: 1

README

wslt

websocket

go get -u github.com/atcharles/wslt

Documentation

Index

Constants

View Source
const (
	KB int64 = 1 << (10 * iota) // 1 << (10*1)
	MB                          // 1 << (10*2)
	GB                          // 1 << (10*3)
	TB                          // 1 << (10*4)
)

Variables

View Source
var (
	//ErrUnauthorized auth err
	ErrUnauthorized = errors.New(http.StatusText(http.StatusUnauthorized))
)
View Source
var (
	Return = new(ReturnJSON)
)
View Source
var (
	StdLogger = log.New(os.Stdout, "[WSlt] ", log.LstdFlags)
)

Functions

This section is empty.

Types

type BusinessHandler

type BusinessHandler func(*Context)

type BusinessMessage

type BusinessMessage struct {
	StringType string

	Data jsoniter.RawMessage
}

func DecodeBiMessage

func DecodeBiMessage(data []byte) (msg *BusinessMessage, err error)

func NewBusinessMessage

func NewBusinessMessage(stringType string, data interface{}) (msg *BusinessMessage, err error)

func (*BusinessMessage) UnmarshalData

func (b *BusinessMessage) UnmarshalData(v interface{}) error

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(urlStr string) (ws *Client, err error)

func (*Client) AddCallHandler

func (c *Client) AddCallHandler(rid string, handler ws_rpc.CallHandler)

func (*Client) Close

func (c *Client) Close()

func (*Client) CloseChan

func (c *Client) CloseChan() <-chan byte

func (*Client) Dial

func (c *Client) Dial(urlStr string) (err error)

func (*Client) GetHandler

func (c *Client) GetHandler(rid string) (handler ws_rpc.CallHandler, ok bool)

func (*Client) IsClosed

func (c *Client) IsClosed() (closed bool)

func (*Client) ReadHandle

func (c *Client) ReadHandle(typeStr string, handler ClientBusinessHandler)

ReadHandle 设置客户端读取操作函数

func (*Client) RemoveHandler

func (c *Client) RemoveHandler(rid string)

func (*Client) SendMessage

func (c *Client) SendMessage(typeString string, msgData interface{}) (err error)

SendMessage msgData is a BusinessMessage's RawData

type ClientBusinessHandler

type ClientBusinessHandler func(*ClientContext)

type ClientContext

type ClientContext struct {
	*Client
	Message *BusinessMessage
}

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection a websocket connection

func (*Connection) Close

func (c *Connection) Close()

func (*Connection) Connector

func (c *Connection) Connector() Connector

func (*Connection) GetConn

func (c *Connection) GetConn() (conn *websocket.Conn)

func (*Connection) IsClosed

func (c *Connection) IsClosed() (closed bool)

func (*Connection) SendMessage

func (c *Connection) SendMessage(businessType string, businessMessage interface{}) (err error)

func (*Connection) SessionID

func (c *Connection) SessionID() int64

func (*Connection) Ws

func (c *Connection) Ws() *WSocket

type Connector

type Connector interface {
	//SetConnection ...
	SetConnection(conn *Connection)
	Connection() *Connection
	//CheckAuth check the connector's Auth
	NewInstance() Connector
	CheckAuth(token string, wConn *websocket.Conn) error

	GetID() int64
}

Connector example:a user

type ConnectorHandler

type ConnectorHandler func() Connector

type Context

type Context struct {
	*Connection
	Message *BusinessMessage
}

func (*Context) BindCallRequest

func (ctx *Context) BindCallRequest() (msg *ws_rpc.CallMsg, err error)

func (*Context) SendCallBackMsg

func (ctx *Context) SendCallBackMsg(callMsg *ws_rpc.CallMsg, data interface{})

SendCallBackMsg Sending synchronous messages

type IterationConnectionsFunc

type IterationConnectionsFunc func(id int64, connection *Connection) bool

WSocket ...

type RawClient

type RawClient struct {
	// contains filtered or unexported fields
}

func NewRawClient

func NewRawClient(urlStr string) (ws *RawClient, err error)

func (*RawClient) Close

func (c *RawClient) Close()

func (*RawClient) CloseChan

func (c *RawClient) CloseChan() <-chan byte

func (*RawClient) Dial

func (c *RawClient) Dial(urlStr string) (err error)

func (*RawClient) IsClosed

func (c *RawClient) IsClosed() (closed bool)

func (*RawClient) ReadMessage

func (c *RawClient) ReadMessage() (raw []byte, err error)

func (*RawClient) SendMessage

func (c *RawClient) SendMessage(typeString string, msgData interface{}) (err error)

msgData is a BusinessMessage's RawData

type ReturnJSON

type ReturnJSON struct {
	Code       int         `json:"code"`
	StatusText string      `json:"status_text"`
	Message    interface{} `json:"message,omitempty"`
}

func (*ReturnJSON) Ok

func (r *ReturnJSON) Ok(i interface{}) *ReturnJSON

func (*ReturnJSON) Set

func (r *ReturnJSON) Set(code int, msg interface{}) *ReturnJSON

type Session

type Session struct {
	SID int64 `json:"sid"`
	// contains filtered or unexported fields
}

func GlobalSession

func GlobalSession() *Session

GlobalSession init globalSession

func (*Session) GetSidsByConnectorID

func (s *Session) GetSidsByConnectorID(ctID int64) (sids []int64)

func (*Session) UnUsedSids

func (s *Session) UnUsedSids() []int64

type SessionRelationShip

type SessionRelationShip struct {
	// contains filtered or unexported fields
}

type WSocket

type WSocket struct {
	// contains filtered or unexported fields
}

WSocket ...

func New

func New() *WSocket

func (*WSocket) Handler

func (w *WSocket) Handler(connector Connector) http.HandlerFunc

func (*WSocket) IterationConnections

func (w *WSocket) IterationConnections(fn IterationConnectionsFunc)

func (*WSocket) ReadHandle

func (w *WSocket) ReadHandle(msgType string, handler BusinessHandler)

func (*WSocket) SendToAll

func (w *WSocket) SendToAll(msgType string, data interface{}) (err error)

type WebContext

type WebContext struct {
	// contains filtered or unexported fields
}

func (*WebContext) IsWebSocket

func (c *WebContext) IsWebSocket() bool

func (*WebContext) JSON

func (c *WebContext) JSON(code int, data interface{})

type WsMessage

type WsMessage struct {
	MessageType int

	Data []byte
}

func CreateWsMessage

func CreateWsMessage(msgType string, data interface{}) (msg *WsMessage, err error)

func NewWsMessage

func NewWsMessage(messageType int, date []byte) *WsMessage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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