models

package
v0.0.0-...-622c2fc Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RoomPool = make([]*Room, 0)

Room Pool containing all rooms currently active

Functions

func AddRoom

func AddRoom(r *Room)

func GetAllClients

func GetAllClients() int

GetAllClients returns the number of all connected clients

func GetNumberOfRooms

func GetNumberOfRooms() int

GetNumberOfRooms get the number of all rooms

func ListRooms

func ListRooms() (int, []string)

ListRooms return the number of registered rooms and a slice of strings with all room names in pool

func PoolBroadcast

func PoolBroadcast(m Message)

PoolBroadcast send a message to all clients of the Pool

func RemoveClient

func RemoveClient(c *Client)

RemoveClient removes a client from a room if the client is the only client in the room the room is also removed from the RoomPool

func RemoveRoom

func RemoveRoom(r *Room)

RemoveRoom removes domain from the DomainPool

Types

type Client

type Client struct {
	Id         string
	Room       string
	Connection *websocket.Conn
}

Client represents an entity connected using a websocket Connection the websocket connection

func NewClient

func NewClient(ws *websocket.Conn, room string) *Client

NewClient instantiate a new websocket client

func (Client) SendMessage

func (c Client) SendMessage(msg Message)

SendMessage sends a message to a connected websocket client

type Message

type Message struct {
	Timestamp string
	Data      map[string]string
}

Message type that will be transmitted over the wire

func NewMessage

func NewMessage(data map[string]string) Message

NewMessage instantiate a new message to be transmitted to websoket client(s)

type Room

type Room struct {
	Name       string
	Public     bool
	ClientPool []*Client
}

A Room containing a Pool of WebSocket clients each time a websocket client connects, it is added to the ClientPool so we can reference at a later time

func FindRoom

func FindRoom(d string) (int, *Room)

FindRoom finds a room in the RoomPool and returns its index and value. If the room does not exist in pool returns -1 If the RoomPool is empty returns -1

func NewRoom

func NewRoom(name string) *Room

NewRoom create a new Room

func (*Room) AddClient

func (r *Room) AddClient(client *Client)

AddClient add a client in client pool

func (*Room) ClientCount

func (r *Room) ClientCount() int

ClientCount returns the number of domain's connected clients

func (*Room) DeleteClient

func (r *Room) DeleteClient(c *Client)

DeleteClient removes a client from the pool

func (*Room) FindClient

func (r *Room) FindClient(c *Client) (int, *Client)

FindClient finds a client in the ClientPool and returns its index and value. If the room does not exists in pool returns -1 If the ClientPool is empty returns -1

func (*Room) HasClient

func (r *Room) HasClient(client *Client) bool

HasClient checks if the room has a client registered in its pool

func (*Room) ListClients

func (r *Room) ListClients() []string

ListClients returns a slice with IDs of all connected clients

func (*Room) RoomBroadcast

func (r *Room) RoomBroadcast(msg Message)

RoomBroadcast send a Message to all domain's connected clients

type User

type User struct {
	Id               int
	Username         string `orm:"unique"`
	Password         string
	Email            string `orm:"unique"`
	EmailConfirmed   bool
	ConfirmationCode string    // used during registration confirmation TODO move to sepparate table and tight up security
	Created          time.Time `orm:"auto_now_add;type(datetime)"`
	LastLogin        time.Time `orm:"type(datetime)"`
	// use this to set different user types, such as Admin, Staff, User, etc
	// for more complex situtations a Roles and a Roles_Permissions models could be more of help
	Role   string
	Active bool // use to lock down the account
}

func AllUsers

func AllUsers() []*User

AllUsers return all stored users from the database

func AuthenticateUser

func AuthenticateUser(usernameOrEmail, password string) (bool, User, string)

Authenticate authenticates a User by his username or email and his password Uppon successful authentication returns true, the User object and an empty string When unsuccessful, returns false, empty User object and a string with the error message

func GetUser

func GetUser(id int) *User

GetUser searches the database for a user object with the given ID

func GetUserByEmail

func GetUserByEmail(email string) *User

GetUserByUsername searches the database for a user object with the given email

func GetUserByUsername

func GetUserByUsername(username string) *User

GetUserByUsername searches the database for a user object with the given username

func New

func New(username, password, email, role string) *User

New creates and returns a new User object. To save the new object use the Save method.

func (*User) Delete

func (u *User) Delete() error

Delete deletes a user object from database

func (*User) Save

func (u *User) Save() error

Save saves a User object to database

Jump to

Keyboard shortcuts

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