database

package
v0.0.0-...-d9e0560 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound = errors.New("account not found")
	ErrAccountExists   = errors.New("account already exists")
	ErrNoDatabase      = errors.New("no database connection details, (i.e POSTGRESQL_URL)")
	ErrNoPasswordGiven = errors.New("a password is required")
)
View Source
var TOKEN_LENGTH = 32

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

Types

type Account

type Account struct {
	ID                 string `sql:"type:uuid;primary key;default:uuid_generate_v1mc()"`
	Name               string `gorm:"default:null"`
	Email              string `gorm:"default:null"`
	Username           string `gorm:"default:null"`
	PhoneNo            string `gorm:"default:null"`
	HashedPassword     string `db:"hashed_password"`
	ConfirmationToken  string `gorm:"default:null"`
	PasswordResetToken string `gorm:"default:null"`
	CreatedAt          time.Time
	UpdatedAt          time.Time
}

func (*Account) BeforeCreate

func (a *Account) BeforeCreate(scope *gorm.Scope) error

func (*Account) ComparePasswordToHash

func (a *Account) ComparePasswordToHash(password string) error

func (*Account) HashPassword

func (a *Account) HashPassword(password string) error

type Database

type Database interface {
	List(count int32, token string) ([]*Account, string, error)
	Get(id, email string) (*Account, error)
	Search(query string) ([]*Account, error)
	Create(a *Account, password string) error
	Update(a *Account) error
	Delete(ID string) error
	GeneratePasswordToken(id, email string) (*Account, error)
	UpdatePassword(string, string) (*Account, error)
	Migrate() error
	Truncate() error
	Close() error
}

func DatabaseFromEnv

func DatabaseFromEnv() Database

type PostgreSQL

type PostgreSQL struct {
	Database

	DB *gorm.DB
	// contains filtered or unexported fields
}

func (*PostgreSQL) Close

func (p *PostgreSQL) Close() error

func (*PostgreSQL) Confirm

func (p *PostgreSQL) Confirm(token string) (*Account, error)

func (*PostgreSQL) Connect

func (p *PostgreSQL) Connect(conn string) error

func (*PostgreSQL) Create

func (p *PostgreSQL) Create(a *Account, password string) error

func (*PostgreSQL) Delete

func (p *PostgreSQL) Delete(ID string) error

func (*PostgreSQL) GeneratePasswordToken

func (p *PostgreSQL) GeneratePasswordToken(id, email string) (*Account, error)

func (*PostgreSQL) Get

func (p *PostgreSQL) Get(id, email string) (*Account, error)

func (*PostgreSQL) List

func (p *PostgreSQL) List(count32 int32, token string) (accounts []*Account, next_token string, err error)

func (*PostgreSQL) Migrate

func (p *PostgreSQL) Migrate() error

func (*PostgreSQL) Search

func (p *PostgreSQL) Search(query string) (accounts []*Account, err error)

func (*PostgreSQL) Truncate

func (p *PostgreSQL) Truncate() error

func (*PostgreSQL) Update

func (p *PostgreSQL) Update(a *Account) error

func (*PostgreSQL) UpdatePassword

func (p *PostgreSQL) UpdatePassword(token, hashed_password string) (*Account, error)

Jump to

Keyboard shortcuts

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