action

package
v0.0.0-...-897d125 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// key for the action field in AnyMessage.
	KeyAction   = "action"
	KeySenderID = "sender_id"
	KeyRoomID   = "room_id"
)
View Source
const SupportedTimeFormat = time.RFC3339

SupportedTimeFormat is time representation format to be acceptable for the application. all of the time representation format should be in manner of this format.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action indicates a action type for the JSON data schema.

const (
	// no meaning action
	ActionEmpty Action = ""

	// internal server error
	ActionError Action = "ERROR"

	// server to front-end client
	ActionUserConnect    Action = "USER_CONNECT"
	ActionUserDisconnect Action = "USER_DISCONNECT"

	ActionCreateRoom       Action = "CREATE_ROOM"
	ActionDeleteRoom       Action = "DELETE_ROOM"
	ActionAddRoomMember    Action = "ADD_ROOM_MEMBER"
	ActionRemoveRoomMember Action = "REMOVE_ROOM_MEMBER"

	// server from/to front-end client
	ActionReadMessage Action = "READ_MESSAGE"
	ActionChatMessage Action = "CHAT_MESSAGE"

	ActionTypeStart Action = "TYPE_START"
	ActionTypeEnd   Action = "TYPE_END"
)

type ActionMessage

type ActionMessage interface {
	Action() Action
}

ActionMessage can return its action.

func ConvertAnyMessage

func ConvertAnyMessage(m AnyMessage) (ActionMessage, error)

Convert AnyMessage to ActionMessage specified by AnyMessage.Action(). it returns error if AnyMessage has invalid data structure.

type AddRoomMember

type AddRoomMember struct {
	EmbdFields

	SenderID  uint64 `json:"sender_id"`
	RoomID    uint64 `json:"room_id"`
	AddUserID uint64 `json:"add_user_id"`
}

AddRoomMember indicates action for adding new room member it implements ActionMessage interface.

func ParseAddRoomMember

func ParseAddRoomMember(m AnyMessage, action Action) (AddRoomMember, error)

type AnyMessage

type AnyMessage map[string]interface{}

AnyMessage is a arbitrary message through the websocket. it implements ActionMessage interface.

func (AnyMessage) Action

func (a AnyMessage) Action() Action

get action from any message which indicates what action is contained any message. return empty action if no action exist.

func (AnyMessage) Array

func (a AnyMessage) Array(key string) []interface{}

func (AnyMessage) Number

func (a AnyMessage) Number(key string) float64

func (AnyMessage) Object

func (a AnyMessage) Object(key string) map[string]interface{}

func (AnyMessage) SetNumber

func (a AnyMessage) SetNumber(key string, val float64)

func (AnyMessage) SetString

func (a AnyMessage) SetString(key string, val string)

func (AnyMessage) String

func (a AnyMessage) String(key string) string

func (AnyMessage) Time

func (a AnyMessage) Time(key string) time.Time

func (AnyMessage) UInt64

func (a AnyMessage) UInt64(key string) uint64

func (AnyMessage) UInt64s

func (a AnyMessage) UInt64s(key string) []uint64

type ChatActionFields

type ChatActionFields struct {
	EmbdFields
	RoomID   uint64 `json:"room_id,omitempty"`
	SenderID uint64 `json:"sender_id,omitempty"` // it is overwritten by the server
}

common fields for the websocket message to be used to chat context. it implements ChatActionMessage interface. TODO: remove

func (ChatActionFields) GetRoomID

func (tr ChatActionFields) GetRoomID() uint64

func (ChatActionFields) GetSenderID

func (tr ChatActionFields) GetSenderID() uint64

func (*ChatActionFields) ParseFields

func (fields *ChatActionFields) ParseFields(m AnyMessage)

helper function for parsing fields from AnyMessage. it will load RoomID and SenderID from AnyMessage.

type ChatMessage

type ChatMessage struct {
	EmbdFields
	RoomID   uint64 `json:"room_id,omitempty"`
	SenderID uint64 `json:"sender_id,omitempty"` // it is overwritten by the server
	Content  string `json:"content,omitempty"`
}

ChatMessage is chat message which is recieved from a browser-side client and sends to other clients in the same room. it implements ChatActionMessage interface.

func ParseChatMessage

func ParseChatMessage(m AnyMessage, action Action) (ChatMessage, error)

type CreateRoom

type CreateRoom struct {
	EmbdFields

	SenderID      uint64   `json:"sender_id"`
	RoomName      string   `json:"room_name"`
	RoomMemberIDs []uint64 `json:"room_member_ids"`
}

CreateRoom indicates action for a request for creating room. it implements ActionMessage interface.

func ParseCreateRoom

func ParseCreateRoom(m AnyMessage, action Action) (CreateRoom, error)

type DeleteRoom

type DeleteRoom struct {
	EmbdFields

	SenderID uint64 `json:"sender_id"`
	RoomID   uint64 `json:"room_id"`
}

DeleteRoom indicates action for a request for deleting room. it implements ActionMessage interface.

func ParseDeleteRoom

func ParseDeleteRoom(m AnyMessage, action Action) (DeleteRoom, error)

type EmbdFields

type EmbdFields struct {
	ActionName Action `json:"action,omitempty"`
}

common fields for the websocket action message structs. it implements ActionMessage interface.

func (EmbdFields) Action

func (ef EmbdFields) Action() Action

func (*EmbdFields) ParseFields

func (ef *EmbdFields) ParseFields(m AnyMessage)

helper function for parsing fields from AnyMessage. it will load Action from AnyMessage.

type ErrorMessage

type ErrorMessage struct {
	EmbdFields
	ErrorMsg string        `json:"error,omitempty"`
	Cause    ActionMessage `json:"cause,omitempty"`
}

Error message. it implements ActionMessage interface.

func NewErrorMessage

func NewErrorMessage(err error, cause ...ActionMessage) ErrorMessage

func ParseErrorMessage

func ParseErrorMessage(m AnyMessage, action Action) (ErrorMessage, error)

type QueryRoomMessages

type QueryRoomMessages struct {
	RoomID uint64
	Before Timestamp `json:"before" query:"before"`
	Limit  int       `json:"limit" query:"limit"`
}

QueryRoomMessages is a query for messages in specified room.

type QueryUnreadRoomMessages

type QueryUnreadRoomMessages struct {
	RoomID uint64
	Limit  int `json:"limit" query:"limit"`
}

QueryUnreadRoomMessages is a query for unread messages by user in specified room.

type ReadMessages

type ReadMessages struct {
	EmbdFields
	RoomID   uint64    `json:"room_id,omitempty"`
	SenderID uint64    `json:"sender_id,omitempty"` // it is overwritten by the server
	ReadAt   time.Time `json:"read_at"`
}

ReadMessages indicates notification which some chat messages are read by any user. it implements ChatActionMessage interface.

func ParseReadMessage

func ParseReadMessage(m AnyMessage, action Action) (ReadMessages, error)

type RemoveRoomMember

type RemoveRoomMember struct {
	EmbdFields

	SenderID     uint64 `json:"sender_id"`
	RoomID       uint64 `json:"room_id"`
	RemoveUserID uint64 `json:"remove_user_id"`
}

RemoveRoomMember indicates action for removing room member. it implements ActionMessage interface.

func ParseRemoveRoomMember

func ParseRemoveRoomMember(m AnyMessage, action Action) (RemoveRoomMember, error)

type Timestamp

type Timestamp time.Time

Timestamp is Time data which implements some custom encoders and decoders.

func TimestampNow

func TimestampNow() Timestamp

TimestampNow is shorthand for Timestamp(time.Now()).

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

implements json.Marshaler interface.

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() ([]byte, error)

implements json.TextMarshaler interface.

func (Timestamp) Time

func (t Timestamp) Time() time.Time

Time returns its internal representation as time.Time.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

implements json.Unmarshaler interface.

func (*Timestamp) UnmarshalParam

func (t *Timestamp) UnmarshalParam(src string) error

implements github.com/labstack/echo.BindUnmarshaler interface.

type TypeEnd

type TypeEnd struct {
	ChatActionFields

	// set by server and return client
	SenderName string    `json:"sender_name,omitempty"`
	EndAt      time.Time `json:"end_at,omitempty"`
}

TypeEnd indicates user ends key typing. it implements ChatActionMessage interface.

func ParseTypeEnd

func ParseTypeEnd(m AnyMessage, action Action) (TypeEnd, error)

type TypeStart

type TypeStart struct {
	ChatActionFields

	// set by server and return client
	SenderName string    `json:"sender_name,omitempty"`
	StartAt    time.Time `json:"start_at,omitempty"`
}

TypeStart indicates user starts key typing. it implements ChatActionMessage interface.

func ParseTypeStart

func ParseTypeStart(m AnyMessage, action Action) (TypeStart, error)

type UserConnect

type UserConnect struct {
	EmbdFields
	UserID uint64 `json:"user_id,omitempty"`
}

UserConnect indicates connect acitve user to chat server. it implements ActionMessage interface

func NewUserConnect

func NewUserConnect(userID uint64) UserConnect

type UserDisconnect

type UserDisconnect UserConnect

UserDisconnect indicates disconnect acitve user to chat server. it implements ActionMessage interface

func NewUserDisconnect

func NewUserDisconnect(userID uint64) UserDisconnect

Jump to

Keyboard shortcuts

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