db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetCollectionName

func SetCollectionName(colname string) func(*MGO) error

SetCollectionName changes the name of the mongodb collection.

func SetDBName

func SetDBName(dbname string) func(*MGO) error

SetDBName changes the name of the mongodb database.

func SetURL

func SetURL(url string) func(*MGO) error

SetURL changes the url to which the connection should be established.

Types

type Database

type Database interface {
	Connect() error
	Disconnect() error
	FindUserByMail(string) (*User, error)
	FindUserByID(string) (*User, error)
}

Database describe all database interaction.

func NewMongoConnection

func NewMongoConnection(opts ...func(*MGO) error) (Database, error)

NewMongoConnection creates a new mongo database connection. It takes functional parameters to change default options such as the mongo url It returns the newly created server or an error if something went wrong.

type MGO

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

MGO implements the database interface, representing a mongodb connection.

func (MGO) Connect

func (m MGO) Connect() error

Connect establishes a connection to a mongodb server.

func (MGO) Disconnect

func (MGO) Disconnect() error

Disconnect closes the connection to the mongodb server.

func (MGO) FindUserByID

func (MGO) FindUserByID(id string) (*User, error)

FindUserByID searches for a user with the given id.

func (MGO) FindUserByMail added in v0.2.0

func (MGO) FindUserByMail(mail string) (*User, error)

FindUserByMail searches for a user with the given mail address.

type User

type User struct {
	ID       primitive.ObjectID `bson:"_id,omitempty"`
	Mail     string             `bson:"mail"`
	Password string             `bson:"password"`
	Roles    []string           `bson:"roles"`
}

User represents a user document.

func (*User) ValidatePassword

func (u *User) ValidatePassword(plainPassword string) error

ValidatePassword validates the given plaintext password for the user

Jump to

Keyboard shortcuts

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