mdb

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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

func NewChat(name, password string, isHidden bool) *Chat

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

func (c *Chat) ValidPassword(password string) bool

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

func CreateConnection(mongoURL, dbName string) (*Database, error)

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

func NewMessage

func NewMessage(chatName string, timestamp int64, sender string) *Message

NewMessage creates a new instance of the Message object

type MessageContent

type MessageContent struct {
	Recipient string `bson:"recipient"`
	Content   []byte `bson:"content"`
}

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.

type User

type User struct {
	ID        bson.ObjectId `bson:"_id"`
	Username  string        `bson:"username"`
	PublicKey []byte        `bson:"public_key"`
}

User is the model of a user stored in the database

func NewUser

func NewUser(username string, publicKey []byte) *User

NewUser creates a new instance of the user object

Jump to

Keyboard shortcuts

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