db

package
v0.0.0-...-1f40b3c Latest Latest
Warning

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

Go to latest
Published: Jun 9, 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 DB

type DB interface {
	Clone() DB
	Copy() DB
	Close()
	Users() UserManager
	RefreshTokens() RefreshTokenManager
	Permissions() PermissionManager
	Migrations() MigrationManager
	Devices() DeviceManager
}

DB implementation is what newsletter depends on in case some other db is preferred, all one would have to do is to simply implement the db interface

func GetDbImplementation

func GetDbImplementation(session *mgo.Session) DB

GetDbImplementation Returns database implementation of DB interface

type DatabaseLayer

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

DatabaseLayer is implementation of DB interface

func (DatabaseLayer) Clone

func (db DatabaseLayer) Clone() DB

Clone works just like Copy, but also reuses the same socket as the original session, in case it had already reserved one due to its consistency guarantees. This behavior ensures that writes performed in the old session are necessarily observed when using the new session, as long as it was a strong or monotonic session. That said, it also means that long operations may cause other goroutines using the original session to wait.

func (DatabaseLayer) Close

func (db DatabaseLayer) Close()

Close terminates the session. It's a runtime error to use a session after it has been closed.

func (DatabaseLayer) Copy

func (db DatabaseLayer) Copy() DB

Copy works just like New, but preserves the exact authentication information from the original session.

func (DatabaseLayer) Devices

func (db DatabaseLayer) Devices() DeviceManager

Devices returns implementation of DeviceManager

func (DatabaseLayer) Migrations

func (db DatabaseLayer) Migrations() MigrationManager

Migrations returns MigrationManager

func (DatabaseLayer) Permissions

func (db DatabaseLayer) Permissions() PermissionManager

Permissions returns PermissionManager

func (DatabaseLayer) RefreshTokens

func (db DatabaseLayer) RefreshTokens() RefreshTokenManager

RefreshTokens returns RefreshTokenManager

func (DatabaseLayer) Users

func (db DatabaseLayer) Users() UserManager

Users returns UserManager

type Device

type Device struct {
	Token string
}

Device struct to represent a device

type DeviceManager

type DeviceManager interface {
	Register(token string) error
	Exists(token string) (bool, error)
	FindByToken(token string) (*Device, error)
}

DeviceManager interface to satisfied for managing devices

func GetDeviceManager

func GetDeviceManager(db *mgo.Database) DeviceManager

GetDeviceManager returns an implementation of DeviceManager

type MigrationInfo

type MigrationInfo struct {
	Key         string    `json:"key"`
	Description string    `json:"description"`
	AppliedAt   time.Time `json:"applied_at"`
}

MigrationInfo information about migration

type MigrationManager

type MigrationManager interface {
	MarkApplied(key string, description string) error
	IsApplied(key string) (bool, error)
}

MigrationManager deals with any info related to migration saved to disk

func GetMigrationManager

func GetMigrationManager(db *mgo.Database) MigrationManager

GetMigrationManager returns implementation of MigrationManager

type Permission

type Permission struct {
	Key         string `json:"key"`
	Description string `json:"description"`
}

Permission struct, key is the unique permission key, description is human readable description of permission

type PermissionManager

type PermissionManager interface {
	Create(key string, description string) error
	Exists(key string) (bool, error)
	List() ([]Permission, error)
}

PermissionManager deals with Permission persistence

func GetPermissionManager

func GetPermissionManager(db *mgo.Database) PermissionManager

GetPermissionManager returns an implementation of PermissionManager

type RefreshToken

type RefreshToken struct {
	Token string `json:"token"`
	User  string `json:"user"`
}

RefreshToken representation of a Refresh Token

type RefreshTokenManager

type RefreshTokenManager interface {
	FindOne(token string) (*RefreshToken, error)
	Add(token string, user string) error
	List(user string) ([]RefreshToken, error)
	Delete(token string) error
}

RefreshTokenManager deals with persistence of RefreshTokens

func GetRefreshTokenManager

func GetRefreshTokenManager(db *mgo.Database) RefreshTokenManager

GetRefreshTokenManager returns implementation of RefreshTokenManager

type User

type User struct {
	ID          bson.ObjectId `json:"_id" bson:"_id,omitempty"`
	Email       string        `json:"email"`
	Password    string        `json:"password"`
	Permissions []string      `json:"permissions"`
}

User is representation of a user

type UserLayer

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

UserLayer is implementation of UserManager interface

func (UserLayer) Create

func (dbLayer UserLayer) Create(user User) error

Create a user, returns error if there's one

func (UserLayer) FindByEmail

func (dbLayer UserLayer) FindByEmail(email string) (*User, error)

FindByEmail given email, returns a User

func (UserLayer) FindByID

func (dbLayer UserLayer) FindByID(id string) (*User, error)

FindByID given id of user, returns a User

func (UserLayer) List

func (dbLayer UserLayer) List() ([]User, error)

List users

func (UserLayer) Update

func (dbLayer UserLayer) Update(id string, user User) error

Update a user by id

type UserManager

type UserManager interface {
	FindByEmail(email string) (*User, error)
	FindByID(id string) (*User, error)
	Create(user User) error
	List() ([]User, error)
	Update(id string, user User) error
}

UserManager deals with anything related to User Persistence

func GetUserManager

func GetUserManager(db *mgo.Database) UserManager

GetUserManager returns implementation of UserManager

Jump to

Keyboard shortcuts

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