Documentation ¶
Index ¶
- Constants
- type ActiveUsers
- type AllUsers
- type Avatar
- type Chatroom
- type Chatrooms
- type DatabaseConnection
- func (dbConn DatabaseConnection) AddAvatar(username, avatarFilePath string) error
- func (dbConn DatabaseConnection) AddDirectMessage(message, username, receivedUsername, chatroomName string) error
- func (dbConn DatabaseConnection) AddMessage(message, username, chatroomName string) error
- func (dbConn DatabaseConnection) ChangePassword(userId int64, password string) error
- func (dbConn DatabaseConnection) ChangeUserRoom(username string, room string) error
- func (dbConn DatabaseConnection) ChangeUserStatus(username string, status bool) error
- func (dbConn DatabaseConnection) CheckIfChatroomExists(name string) bool
- func (dbConn DatabaseConnection) CheckIfUserExists(username string) bool
- func (dbConn DatabaseConnection) CompareAvatarSlice(slice1, slice2 []Avatar) bool
- func (dbConn DatabaseConnection) CreateChatroom(name string) error
- func (dbConn DatabaseConnection) CreateUser(username, password string) error
- func (dbConn DatabaseConnection) DeleteMessageById(messageId int64) error
- func (dbConn DatabaseConnection) GetAllAvatars() ([]Avatar, error)
- func (dbConn DatabaseConnection) GetAllChatrooms() (Chatrooms, error)
- func (dbConn DatabaseConnection) GetAllDirectMessages(sender string, receiver string, messageLimit int64) (Messages, error)
- func (dbConn DatabaseConnection) GetAllMessages(chatroom string, messageLimit int64) (Messages, error)
- func (dbConn DatabaseConnection) GetAllUsers() (AllUsers, error)
- func (dbConn DatabaseConnection) GetAvatarByUsername(username string) (Avatar, error)
- func (dbConn DatabaseConnection) GetIdFromChatroomName(name string) int64
- func (dbConn DatabaseConnection) GetMessageCount(chatroom string) int64
- func (dbConn DatabaseConnection) GetNameFromChatroomId(id int64) string
- func (dbConn DatabaseConnection) GetNewestDirectMessages(messageId int64, users []string, messageLimit int64) (Messages, error)
- func (dbConn DatabaseConnection) GetNewestMessagesFrom(messageId int64, chatroom string, messageLimit int64) (Messages, error)
- func (dbConn DatabaseConnection) GetPasswordById(id int64) (string, error)
- func (dbConn DatabaseConnection) GetPasswordByUsername(username string) (string, error)
- func (dbConn DatabaseConnection) GetUserId(username string) (int64, error)
- func (dbConn DatabaseConnection) GetUsernameFromId(id int64) (string, error)
- func (dbConn DatabaseConnection) GetUsernameFromMessageId(messageId int64) string
- func (dbConn DatabaseConnection) GetUsersByStatus(status bool, room string) (ActiveUsers, error)
- func (dbConn DatabaseConnection) VerifyPasswordByUsername(username, password string) bool
- type Message
- type Messages
- type User
Constants ¶
const ( ADD_AVATAR_TO_USER = "UPDATE users SET avatar_id = $1 WHERE id = $2;" ADD_AVATAR = "INSERT INTO avatars VALUES(DEFAULT, DEFAULT, $1);" GET_NEWEST_AVATAR = "SELECT MAX(id) FROM avatars;" GET_AVATAR = "SELECT * FROM full_avatar_info WHERE username = $1" ALL_AVATARS = "SELECT * FROM full_avatar_info;" )
const ( ADD_MESSAGE = "INSERT INTO messages VALUES(DEFAULT, $1, null, $2, $3);" ADD_DIRECT_MESSAGE = "INSERT INTO messages VALUES(DEFAULT, $1, $2, $3, $4);" GET_ALL_MESSAGES = "SELECT * FROM full_messages WHERE name = $1 ORDER BY id DESC LIMIT $2;" GET_NEWEST_MESSAGES = "SELECT * FROM full_messages WHERE id > $1 AND name = $2 ORDER BY id DESC LIMIT $3;" GET_ALL_DIRECT_MESSAGES = "" /* 130-byte string literal not displayed */ GET_NEWEST_DIRECT_MESSAGES = "" /* 153-byte string literal not displayed */ GET_MESSAGE_COUNT = "SELECT count(id) FROM full_messages WHERE name = $1;" GET_USERNAME_FROM_MESSAGE_ID = "SELECT users.username FROM messages INNER JOIN users ON users.id = messages.user_id WHERE messages.id = $1;" DELETE_MESSAGE = "DELETE FROM messages WHERE id = $1;" )
const ( GET_ID_FROM_USERNAME = "SELECT id FROM users WHERE username = $1;" GET_PASSWORD_FROM_ID = "SELECT password FROM users WHERE id = $1;" GET_PASSWORD_FROM_USERNAME = "SELECT password FROM users WHERE username = $1;" GET_USERNAME_FROM_ID = "SELECT username FROM users WHERE id = $1;" UPDATE_USER_STATUS = "UPDATE users SET status = $1 WHERE id = $2;" UPDATE_USER_ROOM = "UPDATE users SET room = $1 WHERE id = $2;" GET_USERNAMES_FROM_STATUS = "SELECT username FROM users WHERE status = $1 AND room = $2;" GET_ALL_USERS = "SELECT username, status, room FROM users WHERE username != 'admin' ORDER BY username ASC;" CHECK_IF_USER_EXISTS = "SELECT EXISTS(SELECT username FROM users WHERE username = $1);" CREATE_USER = "INSERT INTO users VALUES(DEFAULT, $1, $2, $2)" CHANGE_PASSWORD = "UPDATE users SET password = $1 WHERE id = $2;" )
const DATABASE_SETTINGS_FILE = "database_settings.json"
DATABASE_SETTINGS_FILE is the file that will be read to make a postgres url
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveUsers ¶
type ActiveUsers struct {
ActiveUsers []string `json:"activeUsers"`
}
type DatabaseConnection ¶
type DatabaseConnection struct { Username string `json:"username"` Password string `json:"password"` Port string `json:"port"` DatabaseName string `json:"databaseName"` // contains filtered or unexported fields }
DatabaseConnection holds all the important data for the postgres connection
func CreateDatabaseConnection ¶
func CreateDatabaseConnection() DatabaseConnection
Creates the DatabaseConnection object
func (DatabaseConnection) AddAvatar ¶
func (dbConn DatabaseConnection) AddAvatar(username, avatarFilePath string) error
Adds an avatar to a user
func (DatabaseConnection) AddDirectMessage ¶
func (dbConn DatabaseConnection) AddDirectMessage(message, username, receivedUsername, chatroomName string) error
adds a message to the database under the username provided for direct messenging
func (DatabaseConnection) AddMessage ¶
func (dbConn DatabaseConnection) AddMessage(message, username, chatroomName string) error
adds a message to the database under the username provided
func (DatabaseConnection) ChangePassword ¶
func (dbConn DatabaseConnection) ChangePassword(userId int64, password string) error
changes the users password
func (DatabaseConnection) ChangeUserRoom ¶
func (dbConn DatabaseConnection) ChangeUserRoom(username string, room string) error
Changes the users room
func (DatabaseConnection) ChangeUserStatus ¶
func (dbConn DatabaseConnection) ChangeUserStatus(username string, status bool) error
Changes the users status
func (DatabaseConnection) CheckIfChatroomExists ¶
func (dbConn DatabaseConnection) CheckIfChatroomExists(name string) bool
func (DatabaseConnection) CheckIfUserExists ¶
func (dbConn DatabaseConnection) CheckIfUserExists(username string) bool
checks if a user exists
func (DatabaseConnection) CompareAvatarSlice ¶
func (dbConn DatabaseConnection) CompareAvatarSlice(slice1, slice2 []Avatar) bool
Gets all the usernames and their avatar locations
func (DatabaseConnection) CreateChatroom ¶
func (dbConn DatabaseConnection) CreateChatroom(name string) error
func (DatabaseConnection) CreateUser ¶
func (dbConn DatabaseConnection) CreateUser(username, password string) error
checks if a user exists
func (DatabaseConnection) DeleteMessageById ¶
func (dbConn DatabaseConnection) DeleteMessageById(messageId int64) error
deletes the message from the db by using its id
func (DatabaseConnection) GetAllAvatars ¶
func (dbConn DatabaseConnection) GetAllAvatars() ([]Avatar, error)
Gets all the usernames and their avatar locations
func (DatabaseConnection) GetAllChatrooms ¶
func (dbConn DatabaseConnection) GetAllChatrooms() (Chatrooms, error)
func (DatabaseConnection) GetAllDirectMessages ¶
func (dbConn DatabaseConnection) GetAllDirectMessages(sender string, receiver string, messageLimit int64) (Messages, error)
GetAllMessages returns an array of Message types containing all the messages from the database
func (DatabaseConnection) GetAllMessages ¶
func (dbConn DatabaseConnection) GetAllMessages(chatroom string, messageLimit int64) (Messages, error)
GetAllMessages returns an array of Message types containing all the messages from the database
func (DatabaseConnection) GetAllUsers ¶
func (dbConn DatabaseConnection) GetAllUsers() (AllUsers, error)
Gets all the users in the USER DB and their status
func (DatabaseConnection) GetAvatarByUsername ¶
func (dbConn DatabaseConnection) GetAvatarByUsername(username string) (Avatar, error)
Gets the username and its avatar version and location
func (DatabaseConnection) GetIdFromChatroomName ¶
func (dbConn DatabaseConnection) GetIdFromChatroomName(name string) int64
func (DatabaseConnection) GetMessageCount ¶
func (dbConn DatabaseConnection) GetMessageCount(chatroom string) int64
GetMessageCount returns the message count from the database
func (DatabaseConnection) GetNameFromChatroomId ¶
func (dbConn DatabaseConnection) GetNameFromChatroomId(id int64) string
func (DatabaseConnection) GetNewestDirectMessages ¶
func (DatabaseConnection) GetNewestMessagesFrom ¶
func (DatabaseConnection) GetPasswordById ¶
func (dbConn DatabaseConnection) GetPasswordById(id int64) (string, error)
GetUsername gets the users password from the id
func (DatabaseConnection) GetPasswordByUsername ¶
func (dbConn DatabaseConnection) GetPasswordByUsername(username string) (string, error)
GetUsername gets the users password from the id
func (DatabaseConnection) GetUserId ¶
func (dbConn DatabaseConnection) GetUserId(username string) (int64, error)
GetUserId gets the users id from the username
func (DatabaseConnection) GetUsernameFromId ¶
func (dbConn DatabaseConnection) GetUsernameFromId(id int64) (string, error)
GetUsername gets the users username from the id
func (DatabaseConnection) GetUsernameFromMessageId ¶
func (dbConn DatabaseConnection) GetUsernameFromMessageId(messageId int64) string
GetUsernameFromMessageId gets the username from a message id
func (DatabaseConnection) GetUsersByStatus ¶
func (dbConn DatabaseConnection) GetUsersByStatus(status bool, room string) (ActiveUsers, error)
Gets all the users by their status
func (DatabaseConnection) VerifyPasswordByUsername ¶
func (dbConn DatabaseConnection) VerifyPasswordByUsername(username, password string) bool
Verifys the password of a user
type Message ¶
type Message struct { MessageId int64 `json:"messageId"` Username string `json:"username"` ReceivedUsername string `json:"receivedUsername"` Chatroom string `json:"chatroom"` Message string `json:"message"` Timestamp time.Time `json:"timestamp"` }
Message holds all the data for a message from the database