models

package
v0.0.0-...-136d297 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The minimun number of bytes to be used for each session token.
	MinBytesPerToken = 32
)

Variables

This section is empty.

Functions

func Open

func Open(config PostgresConfig) (*sql.DB, error)

Open will open a SQL connection with the provided Postgres database. Callers of Open need to ensure the connection is eventually closed via the db.Close() method.

Types

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	Database string
	SSLMode  string
}

func DefaultPostgresConfig

func DefaultPostgresConfig() PostgresConfig

func (PostgresConfig) String

func (cfg PostgresConfig) String() string

type Session

type Session struct {
	ID     int
	UserID int
	// Token is only set when creating a new session.
	// It will be left empty when look up a session,
	// as we only store the hash of a session token in the database.
	Token     string
	TokenHash string
}

type SessionService

type SessionService struct {
	DB *sql.DB
	// BytesPerToken is used to determine how many bytes to use when
	// generating each session token. If this value is not set or less than
	// the MinBytesPerToken const, the MinBytesPerToken will be used.
	BytesPerToken int
}

func (*SessionService) Create

func (ss *SessionService) Create(userID int) (*Session, error)

func (*SessionService) Delete

func (ss *SessionService) Delete(token string) error

func (*SessionService) User

func (ss *SessionService) User(token string) (*User, error)

type User

type User struct {
	ID           int
	Email        string
	PasswordHash string
}

type UserService

type UserService struct {
	DB *sql.DB
}

func (*UserService) Authenticate

func (us *UserService) Authenticate(email, password string) (*User, error)

func (*UserService) Create

func (us *UserService) Create(email, password string) (*User, error)

Jump to

Keyboard shortcuts

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