data

package
v0.0.0-...-e3cadf0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package data provides the data access layer for the application. It is responsible for interacting with the database layer.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmailOrUsernameExists = fmt.Errorf("user with this email or username already exists")

ErrEmailOrUsernameExists is an error returned when a user with the given email already exists.

Functions

This section is empty.

Types

type Datalayer

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

Datalayer is a struct that helps us to interact with the data.

func New

func New(db UserCredentials, saltLength int, tokenExpirationTime time.Duration, signKey []byte) *Datalayer

New returns a new Datalayer struct.

func (*Datalayer) CreateUser

func (d *Datalayer) CreateUser(ctx context.Context, user models.User) error

CreateUser is a function to create a new user.

func (*Datalayer) GetUserById

func (d *Datalayer) GetUserById(ctx context.Context, id int) (models.UserInfo, error)

func (*Datalayer) SignInUser

func (d *Datalayer) SignInUser(ctx context.Context, username, password string) (string, error)

SignInUser is a function to sign in a user. It returns an authorization token if the user is signed in successfully.

type UserCredentials

type UserCredentials interface {
	HasEmailOrUsername(ctx context.Context, username, email string) (bool, error)
	GetSaltAndHash(ctx context.Context, username string) (salt, hash string, err error)
	InsertUser(ctx context.Context, username, salt, hash, email string) (int, error)
	GetUserInfo(ctx context.Context, userId int) (username, email string, err error)
	GetUserID(ctx context.Context, username string) (int64, error)
	ImportGoldenWords(ctx context.Context, userId int) error
	ImportGoldenWordsForOld(ctx context.Context) error
}

UserCredentials is an interface that represents database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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