storage

package
v0.0.0-...-e8a7617 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package storage provides the Storer, which has all the methods to query the underlying storage database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	User     string
	Password string
	Host     string
	Port     int
	Socket   string
	Name     string
	Logger   *log.Logger
}

Options for New.

type Storer

type Storer struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

Storer is the storage abstraction.

func New

func New(options Options) *Storer

New returns a new Storer with the given options. If no logger is provided, the logs are discarded.

func (*Storer) Connect

func (s *Storer) Connect() error

Connect to the database and ping it to test that it works.

func (*Storer) Login

func (s *Storer) Login(ctx context.Context, email, password string) (*model.User, error)

Login with a given email and password. The password is cleartext and hashed here. Returns the user if succesful, without the password. Note that the password comparison is done no matter what, to combat timing attacks. See https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html#compare-password-hashes-using-safe-functions

func (*Storer) MigrateDown

func (s *Storer) MigrateDown() error

MigrateDown all versions.

func (*Storer) MigrateTo

func (s *Storer) MigrateTo(version uint) error

MigrateTo a specific version. No database connection should be present already, MigrateTo handles connecting.

func (*Storer) MigrateUp

func (s *Storer) MigrateUp() error

MigrateUp all versions.

func (*Storer) Ping

func (s *Storer) Ping(ctx context.Context) error

Ping the db with the given context and runs a "select 1".

func (*Storer) Signup

func (s *Storer) Signup(ctx context.Context, name, email, password string) error

Signup a user. Note that the given password is in cleartext and hashed here.

Jump to

Keyboard shortcuts

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