user

package
v0.0.0-...-9192568 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	CreateUserTable = `` /* 166-byte string literal not displayed */

	AddUser       = "INSERT INTO users(name, password) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING id"
	DeleteUser    = "DELETE FROM users WHERE id = $1"
	GetUserByID   = "SELECT * FROM users WHERE id = $1"
	GetUserByName = "SELECT * FROM users WHERE name = $1"
)

Variables

View Source
var (
	ErrDBMissingURL = errors.New("users db url is missing")
	ErrExists       = errors.New("the user with specified name already exists")
	ErrNotFound     = errors.New("user not found")
)
View Source
var ErrCredMissing = errors.New("the user is missing one or more required fields")

Functions

This section is empty.

Types

type BasicRepo

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

func NewBasicRepo

func NewBasicRepo() *BasicRepo

func (*BasicRepo) AddUser

func (r *BasicRepo) AddUser(_ context.Context, user User) (User, error)

func (*BasicRepo) DeleteUser

func (r *BasicRepo) DeleteUser(_ context.Context, uid string) error

func (*BasicRepo) GetUserByID

func (r *BasicRepo) GetUserByID(_ context.Context, uid string) (User, error)

func (*BasicRepo) GetUserByName

func (r *BasicRepo) GetUserByName(_ context.Context, name string) (User, error)

type DBRepo

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

func NewDBRepo

func NewDBRepo(url string) (*DBRepo, error)

func (*DBRepo) AddUser

func (r *DBRepo) AddUser(ctx context.Context, user User) (User, error)

func (*DBRepo) DeleteUser

func (r *DBRepo) DeleteUser(ctx context.Context, uid string) error

func (*DBRepo) GetUserByID

func (r *DBRepo) GetUserByID(ctx context.Context, uid string) (User, error)

func (*DBRepo) GetUserByName

func (r *DBRepo) GetUserByName(ctx context.Context, name string) (User, error)

type IRepository

type IRepository interface {
	AddUser(ctx context.Context, user User) (User, error)
	DeleteUser(ctx context.Context, uid string) error
	GetUserByID(ctx context.Context, uid string) (User, error)
	GetUserByName(ctx context.Context, name string) (User, error)
}

func NewRepo

func NewRepo(repoURL string) (IRepository, error)

type Service

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

func NewService

func NewService(repoURL string) (Service, error)

NewService returns an instance of the Service with the associated repository.

func (Service) AddUser

func (s Service) AddUser(ctx context.Context, user User) error

AddUser hashes the passed user's password and stores a new user. If the user with the specified name already exists, it returns an error.

func (Service) GetUser

func (s Service) GetUser(ctx context.Context, user User) (User, error)

GetUser gathers the user by its name and compares the passed and the stored passwords. If the passwords don't match, or user is not found in the repository, the methods returns an error.

type User

type User struct {
	ID       string `json:"-"`
	Name     string `json:"name"`
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

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