data

package
v0.0.0-...-9257e39 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectDatabase

func ConnectDatabase(data Database) error

ConnectDatabase is function which load the database.

func DisconnectDatabase

func DisconnectDatabase(data Database) error

DisconnectDatabase is function which disconnect the database.

Types

type Database

type Database interface {
	// The init function of this database.
	InitConnection() error
	// The close function of this database.
	CloseConnection() error
	// Verify that the user information is reasonable.
	CheckUserAuth(user *User) (bool, error)
	// Insert one note to this labnote system.
	InsertOneNote(note *Note) error
	// Insert one file to this labnote system.
	InsertOneFile(file *File) error
	// Request all notes from the database.
	GetAllNotes() (*[]Note, error)
	// Request all files from the database.
	GetAllFiles() (*[]File, error)
}

Database definition of the abstract interface of it.

type File

type File struct {
	Time time.Time `bson:"time"` // upload time of file
	Name string    `bson:"name"` // the name of this file
	Hash string    `bson:"hash"` // the hash of file saved
	Url  string    `bson:"url"`  // url of this file which is used to download
}

File is a structure of server's files.

type MongoDB

type MongoDB struct {
	// contains filtered or unexported fields
}

Here is the definition of the database structure.

func NewMongoDB

func NewMongoDB(cmd string, name string) *MongoDB

func (*MongoDB) CheckUserAuth

func (m *MongoDB) CheckUserAuth(user *User) (bool, error)

CheckUserAuth is a check of if user permissions are correct.

func (*MongoDB) CloseConnection

func (m *MongoDB) CloseConnection() error

CloseConnection is a function close the connection with mongodb.

func (*MongoDB) GetAllFiles

func (m *MongoDB) GetAllFiles() (*[]File, error)

GetAllFiles is used to return all of the files in storage.

func (*MongoDB) GetAllNotes

func (m *MongoDB) GetAllNotes() (*[]Note, error)

GetAllNotes function return all the notes in the database.

func (*MongoDB) InitConnection

func (m *MongoDB) InitConnection() error

InitConnection function initialize the connection to the database.

func (*MongoDB) InsertOneFile

func (m *MongoDB) InsertOneFile(file *File) error

InsertOneFile insert a new file into the database's file collection.

func (*MongoDB) InsertOneNote

func (m *MongoDB) InsertOneNote(note *Note) error

InsertOneNote insert a new note into the database's note collection.

type MySQL

type MySQL struct {
	// contains filtered or unexported fields
}

Here is the definition of the database structure.

func NewMySQL

func NewMySQL(cmd string, name string) *MySQL

func (*MySQL) CheckUserAuth

func (m *MySQL) CheckUserAuth(user *User) (bool, error)

CheckUserAuth is a check of if user permissions are correct.

func (*MySQL) CloseConnection

func (m *MySQL) CloseConnection() error

CloseConnection is a function close the connection with mongodb.

func (*MySQL) GetAllFiles

func (m *MySQL) GetAllFiles() (*[]File, error)

GetAllFiles is used to return all of the files in storage.

func (*MySQL) GetAllNotes

func (m *MySQL) GetAllNotes() (*[]Note, error)

GetAllNotes function return all the notes in the database.

func (*MySQL) InitConnection

func (m *MySQL) InitConnection() error

InitConnection function initialize the connection to the database.

func (*MySQL) InsertOneFile

func (m *MySQL) InsertOneFile(file *File) error

InsertOneFile insert a new file into the database's file collection.

func (*MySQL) InsertOneNote

func (m *MySQL) InsertOneNote(note *Note) error

InsertOneNote insert a new note into the database's note collection.

type Note

type Note struct {
	Time    time.Time `bson:"time"`    // upload time of note
	Content string    `bson:"content"` // content of this note
}

Note is a structure which stored in the database.

type User

type User struct {
	Email    string `bson:"email"`    // user's email address
	Password string `bson:"password"` // user's password
}

User is a structure prototype for database users.

Jump to

Keyboard shortcuts

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