Documentation ¶
Overview ¶
Package common declares common type which are used in both server and client
Index ¶
- Constants
- type DataType
- type Message
- func (m Message) Binary() []byte
- func (m Message) Cmd() string
- func (m Message) CmdType() string
- func (m Message) DataType() DataType
- func (m Message) Error() string
- func (m Message) ExpireDate() time.Time
- func (m Message) From() string
- func (m Message) GetJsonData(key string) interface{}
- func (m Message) Json() ([]byte, error)
- func (m Message) ParseJsonData() (map[string]interface{}, error)
- func (m Message) Status() Status
- func (m Message) String() string
- func (m Message) To() string
- type Status
- type User
Constants ¶
const ( TEXT = 1 BINARY = 2 )
const ( STATUS_OK = 1 STATUS_ERROR = 2 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message represents protocol message. For more detailed information check protocol.txt
func NewMessage ¶
func NewMessage(from string, to string, cmdType string, cmd string, expireDate time.Time, dataType DataType, data interface{}) Message
NewMessage creates a message from params
func NewResponse ¶
NewResponse is helper which generates responses for Message. Used only from server.
func (Message) Binary ¶
Binary parses message payload to binary if message data type is BINARY TODO(itsankoff): Return and error if msg type if TEXT
func (Message) Error ¶
Error tries to parse message payload as error message if message status is STATUS_ERROR. Valid only for messages received from server
func (Message) ExpireDate ¶
ExpireDate returns message's expire date
func (Message) GetJsonData ¶
GetJsonData tries to extract data from message json payload by key
func (Message) ParseJsonData ¶
ParseJsonData tries to parse message payload as map[string]interface{}
func (Message) Status ¶
Status returns the message status. Valid only for messages received from server
type User ¶
type User struct { Id string UserId string In chan *Message Out chan *Message Done chan interface{} }
User represents a chat user In and Out channles are used to send/received messages to/from remote user Id is transport specific id whicle UserId is authentication user id. UserId is used for sending/receiving messages
func (*User) Disconnect ¶
func (u *User) Disconnect()