users

package
v0.0.0-...-9831a62 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = fmt.Errorf("user does not exist")
	ErrAlreadyExists = fmt.Errorf("user already exists")
)

Known errors.

View Source
var (
	ErrInvalidPassword = fmt.Errorf("invalid password")
	ErrUsernameEmpty   = fmt.Errorf("username is empty")
	ErrPasswordEmpty   = fmt.Errorf("password is empty")
)

Known errors.

Functions

This section is empty.

Types

type Config

type Config struct {
	BCryptCost int `yaml:"bcrypt_cost"`
}

Config contains users configuration.

type Service

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

Service allows to manage users resource.

func NewService

func NewService(db *sql.DB, cfg *Config) *Service

NewService returns new users service.

func (*Service) Create

func (s *Service) Create(ctx context.Context, username string, password []byte) (*User, error)

Create creates a new user with the given password.

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id string) (*User, error)

GetByID returns a user by id.

func (*Service) GetByUsername

func (s *Service) GetByUsername(ctx context.Context, username string) (*User, error)

GetByUsername returns a user by id.

type User

type User struct {
	ID       string    `json:"id"`
	Username string    `json:"username"`
	Hash     []byte    `json:"-"`
	Created  time.Time `json:"-"`
}

User is the user model.

func (*User) ValidatePassword

func (u *User) ValidatePassword(password []byte) error

ValidatePassword returns nil if a given password is valid.

Jump to

Keyboard shortcuts

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