Documentation ¶
Index ¶
- type Chat
- type Database
- func (db *Database) DeleteAll()
- func (db *Database) FindAll(collection DatabaseCollection, query interface{}, selector interface{}, ...) error
- func (db *Database) FindOne(collection DatabaseCollection, query interface{}, selector interface{}, ...) error
- func (db *Database) Insert(collection DatabaseCollection, objects ...interface{}) error
- func (db *Database) MakeIndexes()
- type DatabaseCollection
- type Message
- type MessageContent
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chat ¶
type Chat struct { ID bson.ObjectId `bson:"_id"` Timestamp int64 `bson:"timestamp"` Name string `bson:"name"` PasswordHash []byte `bson:"password_hash"` IsHidden bool `bson:"is_hidden"` }
Chat is the model of the chat object stored in the mongoDB database
func NewChat ¶
NewChat creates a new instance of the Chat object. It takes a plaintext password as input, and returns a new Chat object containing the hashed checksum of that password.
func (*Chat) ValidPassword ¶
ValidPassword compares the checksum of a plaintext password to the checksum stored in the Chat object.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database contains the mongoDB session, and provides methods to query the database
func CreateConnection ¶
CreateConnection creates a new connection to the database
func (*Database) DeleteAll ¶
func (db *Database) DeleteAll()
DeleteAll removes all data inside all collections, but not the information about the collections themselves
func (*Database) FindAll ¶
func (db *Database) FindAll(collection DatabaseCollection, query interface{}, selector interface{}, result interface{}) error
FindAll finds one or more documents contained in a specific database collection Takes a bson query and selector document as input. The result is stored in "result".
func (*Database) FindOne ¶
func (db *Database) FindOne(collection DatabaseCollection, query interface{}, selector interface{}, result interface{}) error
FindOne finds one document in the database (the first that matches the supplied query)
func (*Database) Insert ¶
func (db *Database) Insert(collection DatabaseCollection, objects ...interface{}) error
Insert inserts one or more objects into the database, creates a temporary copy of the session for better concurrency performance
func (*Database) MakeIndexes ¶
func (db *Database) MakeIndexes()
MakeIndexes creates necessary indexes and unique constraints for keys in the database
type DatabaseCollection ¶
type DatabaseCollection int
DatabaseCollection is used to refer to allowed database collections in functions
const ( // Users is the collection containing users Users DatabaseCollection = iota // ChatRooms is the collection containing chat rooms ChatRooms // Messages is the collection containing chat messages Messages )
func (DatabaseCollection) String ¶
func (c DatabaseCollection) String() string
type Message ¶
type Message struct { ID bson.ObjectId `bson:"_id"` ChatName string `bson:"chat_name"` Timestamp int64 `bson:"timestamp"` Sender string `bson:"sender"` MessageContent []MessageContent `bson:"message_content"` }
Message is the model of chat messages stored in the database
type MessageContent ¶
MessageContent contains the ciphertext of a chat message addressed to a specific user There should be an entry for each recipient in the chat room when the chat message was sent.