model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HubConstruct = Hub{
	Broadcast:  make(chan WSMessage),
	Register:   make(chan Subscription),
	UnRegister: make(chan Subscription),
	Users:      make(map[string]map[*Connection]bool),
}
View Source
var Upgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
}

Functions

func GetUser

func GetUser(key string, user string) (names []string)

func InitDB

func InitDB()

Types

type Admin

type Admin struct {
	StaffDetails User `bson:",inline"`
	Super        bool `bson:"super" json:"super"`
}

func (*Admin) CheckAdminDetails

func (b *Admin) CheckAdminDetails(password string) error

func (*Admin) CreateAdmin

func (b *Admin) CreateAdmin() error

type Connection

type Connection struct {
	WS *websocket.Conn

	Send chan []byte
}

Connection is an middleman between the websocket connection and the hub.

type CookieData

type CookieData struct {
	ExitTime time.Time
	UUID     string
	Email    string
	Super    bool
}

type CookieDetail

type CookieDetail struct {
	Email      string
	Collection string
	CookieName string
	Path       string
	Data       CookieData
}

func (*CookieDetail) CheckCookie

func (b *CookieDetail) CheckCookie(r *http.Request, w http.ResponseWriter) error

func (CookieDetail) CreateCookie

func (b CookieDetail) CreateCookie(w http.ResponseWriter) error

type File

type File struct {
	MsgType        string `bson:"-" json:"msgType,omitempty"`
	UniqueFileHash string `bson:"_id" json:"fileHash"`
	FileName       string `bson:"fileName" json:"fileName"`
	User           string `bson:"userID" json:"userID"`
	FileSize       string `bson:"fileSize" json:"fileSize"`
	FileType       string `bson:"fileType" json:"fileType"`
	Chunks         int    `bson:"chunks,omitempty" json:"chunks"`
}

File save files making sure they are distinct.

type FileChunks

type FileChunks struct {
	MsgType            string `bson:"-" json:"msgType,omitempty"`
	FileName           string `bson:"-" json:"fileName,omitempty"`
	UniqueFileHash     string `bson:"_id" json:"fileHash,omitempty"`
	CompressedFileHash string `bson:"compressedFileHash" json:"compressedFileHash,omitempty"`
	FileBinary         string `bson:"fileChunk" json:"fileChunk,omitempty"`
	ChunkIndex         int    `bson:"chunkIndex" json:"chunkIndex"`
}

type Hub

type Hub struct {
	// Registered connections.
	Users map[string]map[*Connection]bool

	// Inbound messages from the connections.
	Broadcast chan WSMessage

	// Register requests from the connections.
	Register chan Subscription

	// Unregister requests from connections.
	UnRegister chan Subscription
}

Hub maintains the set of active connections and broadcasts messages to the connections.

func (*Hub) Run

func (h *Hub) Run()

type JoinRequest

type JoinRequest struct {
	RoomID             string   `bson:"_id" json:"roomID"`
	RoomName           string   `bson:"roomName" json:"roomName"`
	RequestingUserName string   `bson:"requestingUserName" json:"requestingUserName"`
	RequestingUserID   string   `bson:"requestingUserID" json:"requestingUserID"`
	Users              []string `bson:"-" json:"users"`
}

type Joined

type Joined struct {
	RoomID      string `json:"roomID"`
	RoomName    string `json:"roomName"`
	Email       string `json:"email"`
	Joined      bool   `json:"joined"`
	MessageType string `bson:"-" json:"msgType"`
}

type Message

type Message struct {
	RoomID      string `bson:"-" json:"roomID,omitempty"`
	Message     string `bson:"message" json:"message,omitempty"`
	FileSize    string `bson:"fileSize,omitempty" json:"fileSize,omitempty"`
	FileHash    string `bson:"fileHash,omitempty" json:"fileHash,omitempty"`
	UserID      string `bson:"userID" json:"userID,omitempty"`
	Name        string `bson:"name" json:"name,omitempty"`
	Index       int    `bson:"index" json:"index,omitempty"`
	Time        string `bson:"time" json:"time,omitempty"`
	Type        string `bson:"type" json:"type,omitempty"`
	MessageType string `bson:"-" json:"msgType,omitempty"`
}

type NewRoomRequest

type NewRoomRequest struct {
	Email       string `json:"email"`
	RoomName    string `json:"roomName"`
	MessageType string `bson:"-" json:"msgType"`
}

type Room

type Room struct {
	RoomID          string    `bson:"_id" json:"email"`
	RoomName        string    `bson:"roomName" json:"roomName"`
	RegisteredUsers []string  `bson:"registeredUsers"`
	Messages        []Message `bson:"messages" json:"messages"`
}

type RoomsJoined

type RoomsJoined struct {
	RoomID   string `bson:"rooomID" json:"roomID"`
	RoomName string `bson:"rooomName" json:"roomName"`
}

type Subscription

type Subscription struct {
	Conn *Connection
	User string
}

func (Subscription) ReadPump

func (s Subscription) ReadPump(user string)

ReadPump pumps messages from the websocket connection to the hub.

func (*Subscription) WritePump

func (s *Subscription) WritePump()

WritePump pumps messages from the hub to the websocket connection.

type User

type User struct {
	Email string `bson:"_id" json:"email"`
	Name  string `bson:"name" json:"name"`
	DOB   string `bson:"age" json:"age"`
	Class string `bson:"class" json:"class"`
	// ID should either be users matric or leading email stripping @....
	ID           string        `bson:"userID" json:"userID"`
	ParentEmail  string        `bson:"parentEmail" json:"parentEmail"`
	ParentNumber string        `bson:"parentNumber" json:"parentNumber"`
	Password     []byte        `bson:"password" json:"password"`
	Faculty      string        `bson:"faculty" json:"faculty"`
	UUID         string        `bson:"loginUUID" json:"uuid"`
	RoomsJoined  []RoomsJoined `bson:"roomsJoined" json:"roomsJoined"`
	JoinRequest  []JoinRequest `bson:"joinRequest" json:"joinRequest"`
}

func (User) CreateUserLogin

func (b User) CreateUserLogin(password string, w http.ResponseWriter) error

func (User) UploadUser

func (b User) UploadUser(r *http.Request) error

type WSMessage

type WSMessage struct {
	Data []byte
	User string
}

Jump to

Keyboard shortcuts

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