Documentation ¶
Index ¶
- func ServerError(w http.ResponseWriter, err error)
- type ClientMap
- type Connection
- type Options
- type Response
- type RoomHandler
- func (h *RoomHandler) CheckToken(rq *http.Request) bool
- func (h *RoomHandler) GetConnection(rq *http.Request) *Connection
- func (h *RoomHandler) Login(w http.ResponseWriter, rq *http.Request)
- func (h *RoomHandler) New(m *ClientMap, name string, roomlist *room.RoomList, chatlog io.Writer, ...) *Connection
- func (h *RoomHandler) Register(w http.ResponseWriter, rq *http.Request)
- func (h *RoomHandler) ServeHTTP(w http.ResponseWriter, rq *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServerError ¶
func ServerError(w http.ResponseWriter, err error)
ServerError handles server errors writing a response to the client and logging the error.
Types ¶
type ClientMap ¶
type ClientMap struct {
// contains filtered or unexported fields
}
ClientMap is a concurrent safe map of clients
func NewClientMap ¶
func NewClientMap() *ClientMap
NewClientMap makes a new ClientMap and starts its handle function.
func (*ClientMap) Add ¶
func (clm *ClientMap) Add(c *Connection) bool
Add adds the client to the map.
func (*ClientMap) Get ¶
func (clm *ClientMap) Get(token string) *Connection
Get returns client with matching token from the map.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is used to pass information between the client and the client object.
func (*Connection) Close ¶
func (cl *Connection) Close()
Close removes the client from any room, deletes its token from the map and stops its timeout function.
func (*Connection) GetMessages ¶
func (cl *Connection) GetMessages(w http.ResponseWriter, rq *http.Request)
GetMessage gets all the messages for a client since the last time they were checked and then removes them from their message list.
func (*Connection) ResetTimeOut ¶
func (cl *Connection) ResetTimeOut()
ResetTimeOut resets the clients timeout timer.
func (*Connection) SendMessage ¶
func (cl *Connection) SendMessage(m message.Message)
SendMessage is used by th client package to forward messages to the connection to be sent to the user.
func (*Connection) Update ¶
func (cl *Connection) Update(w http.ResponseWriter, rq *http.Request)
Update is an alternative to GetMessages that an http client can use to update data with one request. The body should contain a slice of strings representing the different data that the client wants.
type Options ¶
type Options struct { RoomList *room.RoomList ChatLog io.Writer DataFactory clientdata.Factory ClientFactory connections.ClientFactory Origin string }
type RoomHandler ¶
type RoomHandler struct {
// contains filtered or unexported fields
}
RoomHandler handles the HTTP client requests.
func NewRoomHandler ¶
func NewRoomHandler(options Options) *RoomHandler
NewRoomHandler initializes and returns a new roomHandler.
func (*RoomHandler) CheckToken ¶
func (h *RoomHandler) CheckToken(rq *http.Request) bool
CheckToken returns true if the token present and found in clients map.
func (*RoomHandler) GetConnection ¶
func (h *RoomHandler) GetConnection(rq *http.Request) *Connection
GetConnection returns the Connection associated with the "Autorization" token in the header of the request if they are found. If the Client is not present in the map a new client is created and returned.
func (*RoomHandler) Login ¶
func (h *RoomHandler) Login(w http.ResponseWriter, rq *http.Request)
Login takes a login(name, password) from the rq body and tries to log the client in. It will return a response with header "success" = "true" if the login is successful.
func (*RoomHandler) New ¶
func (h *RoomHandler) New(m *ClientMap, name string, roomlist *room.RoomList, chatlog io.Writer, data clientdata.ClientData) *Connection
New creates a new Connection and associated client.
func (*RoomHandler) Register ¶
func (h *RoomHandler) Register(w http.ResponseWriter, rq *http.Request)
Register is used to create new accounts through the http api. It expects a login object in the body representing the account to be created.
func (*RoomHandler) ServeHTTP ¶
func (h *RoomHandler) ServeHTTP(w http.ResponseWriter, rq *http.Request)
ServeHTTP handles requests other than those sent to the REST handler.