Version: v0.0.0-...-6a36c00 Latest Latest

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

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 3 Imported by: 0



Package common declares common type which are used in both server and client



View Source
const (
	TEXT   = 1
View Source
const (
	STATUS_OK    = 1


This section is empty.


This section is empty.


type DataType

type DataType int

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

func NewResponse(msg *Message, key string, response interface{}) *Message

NewResponse is helper which generates responses for Message. Used only from server.

func (Message) Binary

func (m Message) Binary() []byte

Binary parses message payload to binary if message data type is BINARY TODO(itsankoff): Return and error if msg type if TEXT

func (Message) Cmd

func (m Message) Cmd() string

Cmd returns the message command. For more information check protocol.txt

func (Message) CmdType

func (m Message) CmdType() string

CmdType returns command type. For more information check protocol.txt

func (Message) DataType

func (m Message) DataType() DataType

DataType return message payload data type. (TEXT or BINARY)

func (Message) Error

func (m Message) Error() string

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

func (m Message) ExpireDate() time.Time

ExpireDate returns message's expire date

func (Message) From

func (m Message) From() string

From returns message sender

func (Message) GetJsonData

func (m Message) GetJsonData(key string) interface{}

GetJsonData tries to extract data from message json payload by key

func (Message) Json

func (m Message) Json() ([]byte, error)

Json encodes message in json format

func (Message) ParseJsonData

func (m Message) ParseJsonData() (map[string]interface{}, error)

ParseJsonData tries to parse message payload as map[string]interface{}

func (Message) Status

func (m Message) Status() Status

Status returns the message status. Valid only for messages received from server

func (Message) String

func (m Message) String() string

String parses message's payload to string if message data type is TEXT TODO(itsankoff): Return and error if msg type if BINARY

func (Message) To

func (m Message) To() string

To returns message receiver

type Status

type Status int

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 NewUser

func NewUser(id string) *User

func (*User) Disconnect

func (u *User) Disconnect()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL